By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

How to fix "Object not iterable" error?

P: 3
Hey everyone,
I am fairly new to python, and I was working on a google app engine project for a class, and this error came up. I wasn't sure why, because right above it I have the same object type right above it, and when I take the filter off the other, it works fine, I just can't do that or it screws everything up
Expand|Select|Wrap|Line Numbers
  1. def LoginBar():
  2.     user = users.get_current_user()
  3.     greet = Greeting.all()
  4.     info = greet
  5.     greet.filter("username =", user)
  6.     info = Greeting.all()
  7.     url_account_linktext = "Account"
  8.     check = 0
  9.     if user:
  10.         for info in greet:
  11.             if info.username == user:
  12.                 check = 1
  13.                 break
  14.         if check == 0:
  15.             greeting = Greeting()
  16.             greeting.username = users.get_current_user()
  17.             greeting.email = user.email()
  18.             greeting.name = greeting.username.nickname()
  19.             greeting.put()
  20.  
  21.         url = users.create_logout_url('/')
  22.         url_linktext = 'Logout'
  23.     else:
  24.         url = users.create_login_url('/')
  25.         url_linktext = 'Login'
  26.     template_values = {
  27.             'info': info,
  28.             'greetings': greet,
  29.             'url': url,
  30.             'url_linktext': url_linktext,
  31.             'url_account_linktext': url_account_linktext, 
  32.         }
  33.  
If I use the info variable in this code

Expand|Select|Wrap|Line Numbers
  1. {% for greeting in info %}
  2.     <br /><b>{{ greeting.name }}</b><br />
  3. {% endfor %}
  4.  
it throws this exception, but if I put greet in there, whether it is filtered or not, it works. Any ideas why? I really wish I could use greet, but that doesn't work, sadly, because I use it else where for other stuff. Thanks in advance

Edit, here is the traceback
Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 515, in __call__
  3.     handler.get(*groups)
  4.   File "C:\Users\William\Documents\workspace\242Homework2\src\homework\main.py", line 109, in get
  5.     self.response.out.write(template.render(path, values))
  6.   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\template.py", line 143, in render
  7.     return t.render(Context(template_dict))
  8.   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\template.py", line 183, in wrap_render
  9.     return orig_render(context)
  10.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\__init__.py", line 168, in render
  11.     return self.nodelist.render(context)
  12.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\__init__.py", line 705, in render
  13.     bits.append(self.render_node(node, context))
  14.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\__init__.py", line 718, in render_node
  15.     return(node.render(context))
  16.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\defaulttags.py", line 175, in render
  17.     return self.nodelist_true.render(context)
  18.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\__init__.py", line 705, in render
  19.     bits.append(self.render_node(node, context))
  20.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\__init__.py", line 718, in render_node
  21.     return(node.render(context))
  22.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\defaulttags.py", line 99, in render
  23.     values = list(values)
  24. TypeError: 'Greeting' object is not iterable
  25.  
Feb 7 '11 #1
Share this Question
Share on Google+
3 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
It would help if you posted the error message including the traceback.

The assignments you make in LoginBar() don't seem right. You make an assignment to info twice before the if statement, and then again if user evaluates True.

The second block of code posted is not valid Python and would raise a SyntaxError.
Feb 7 '11 #2

P: 3
I added the tracebook, sorry, meant to add that. The last block of code is integrating the python into html, I was half asleep when I asked this, sorry
Feb 7 '11 #3

P: 3
Never mind, it works now...it turns out I needed to put .all onto the iterating object in the for loop. Thanks for your help!
Feb 7 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.