Reputation: 11
Update: Using Django 1.2.1 and Python 2.5.2 as offered by Dreamhost.
I'm having issues with the last part of the Django tutorial where the urls.py is changed to use generic views. After I change the code I get 404's on the pages and even the index stops working.
I have gone over all of my templates to see if that was the issue but I removed any instance of poll and replaced it with object. I have also attached the template for the index/object_list.
I am running this on Dreamhost and the static urls I set with views worked fine.
urls.py
from brsplash.models import Poll
from django.conf.urls.defaults import *
from django.contrib import admin
from django.views.generic import *
admin.autodiscover()
info_dict = {
'queryset': Poll.objects.all(),
}
urlpatterns = patterns('',
(r'^$', 'django.views.generic.list_detail.object_list', info_dict),
(r'^(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', info_dict),
url(r'^(?P<object_id>\d+)/results/$', 'django.views.generic.list_detail.object_detail', dict(info_dict, template_name='brsplash/results.html'), 'poll_results'),
(r'^(?P<poll_id>\d+)/vote/$', 'brsplash.views.vote'),
)
urlpatterns += patterns('',
(r'^admin/', include(admin.site.urls)),
poll_list.html
{% if object_list %}
<ul>
{% for object in object_list %}
<li><a href="{{ object.id }}/">{{ object.question }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available</p>
{% endif %}
Upvotes: 0
Views: 975
Reputation: 11
You can upgrade to Django 1.3 on Dreamhost: blog.oscarcp.com/?p=167 – jturnbull Sep 22 at 9:54
This fixed my issue with the urls.py issue I was having. Once I upgraded to 1.3.1 and changed the code to reflect it, my pages came back.
Upvotes: 1
Reputation: 9116
Django 1.3 introduced class-based generic views which will replace this function-based approach (see the note at the top of the documentation page) so perhaps it's best to use them instead.
With the class-based approach, your new detail-page url would look something like this:
from brsplash.models import Poll
...
from django.views.generic import ListView
urlpatterns = {'',
url(r'^$', ListView.as_view(model=Poll)),
...
}
This approach can be found in part 4 of the tutorial.
N.B.: I tend not to pass the template_name
argument to as_view
because, as stated in the docs:
ListView generic view uses a default template called <app name>/<model name>_list.html
Upvotes: 4