Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was following a django tutorial online (Mike Hibbert's) and at tutuorial 4 he completed the basic articles app and at one point he goes to the url with the extension '/articles/all', all of his objects show up, wheres as when i try it, only the first one appears... its works perfectly when i try to get each object individually with the extension /article/get/<1, 2, 3>...

articles.html:
HTML
<html>
<body>
<h1> Articles </h1>
{% for article in articles %}
<div>
<h2><a href="/article.get/{{ article.id }}/">{{ article.title }}</a></h2>
<p>{{article.body}}</p>
</div>
{% endfor %}
</body>
</html>


article.html:

HTML
<html>
<body>
<h1> {{ article.title }} </h1>
<p> {{article.body}} </p>
</body>
</html?




articles/views.py:
Python
def articles(request):
    return render_to_response('articles.html',
                              {'articles' : Article.objects.all() })
    
                               
                               
                              
def article(request, article_id=1):
    return render_to_response('article.html',
                              {'article' : Article.objects.get(id=article_id) }) 


articles/urls.py:
Python
urlpatterns = patterns('',
    url(r'^all/$', 'article.views.article'),
    url(r'^get/(?P<article_id>\d+)/$', 'article.views.article'),
Posted
Updated 3-Mar-14 2:30am
v2
Comments
nv3 2-Mar-14 8:11am    
Is that a typo in your second line:
return render_to_response('articles.html',
I would have expected 'article.html'. If not, then show us file articles.html, please.
Vidhu Shah 3-Mar-14 8:30am    
I added article.html
Vidhu Shah 3-Mar-14 8:32am    
I have two html templates
nv3 3-Mar-14 17:27pm    
Looks to me as if the problem is in the all() function of your model, which appear to deliver just a single object, instead of the whole list.
Vidhu Shah 3-Mar-14 20:49pm    
when i go to the shell using manage.py and type the all() function, i get all 4 objects...

1 solution

Ask the owner ((Mike Hibbert).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900