python - Object_list always empty -


the app working way. have simple news adding model below:

class news(models.model):     title = models.charfield(max_length=100)         publication_date = models.datefield(auto_now_add=true)     content = models.textfield() 

the view

def homepage(request):   posts= news.objects.all() #.get(title="aaa")   return render_to_response('homepage.html', {'a':posts}) 

and tamplate:

{% b in a.object_list %}    <li> title:{{ b.title }}</li> {%empty %}    empty {% endfor %} 

unfortunately sais 'empty'. if take '.get(title="aaa")' option instead of '.all()' (the commented part) got right title , content of message title 'aaa'. can explain doing wrong? in advance expertise.

edit i'm sorry didn't have written template option off course 'get' verion of template differs. looks this:

 {{a.title}} {{a.content}  

and works printing expected title , message content 'get' works template , 'for' didn't iterate on queryset returned all(). beginner object_list supposed representation queryset passed in render_on_request element of dictionary?

when use get, variable posts contains instance of news. on other hand, if use .all(), posts contain queryset. first suggest use filter instead of get, posts queryset, , therefore wouldn't have such inconsistent behaviour ...


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -