views:

57

answers:

2

I'm trying to get the generic views for a date-based archive working in django. I defined the urls as described in a tutorial, but django returns a 404 error whenever I want to access an url with a variable (such as month or year) in it. It don't even produces a TemplateDoesNotExist-execption. Normal urls without variables work fine.

Here's my updated urlconf:

from django.conf.urls.defaults import *
from zurichlive.zhl.models import Event

info_dict = {
        'queryset': Event.objects.all(),
        'date_field': 'date',
        'allow_future': 'True',
}

urlpatterns += patterns('django.views.generic.date_based',
    (r'events/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', 'object_detail', dict(info_dict, slug_field='slug', template_name='archive/detail.html')),
    (r'^events/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', 'object_detail', dict(info_dict, template_name='archive/list.html')),
    (r'^events/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$','archive_day',dict(info_dict,template_name='archive/list.html')),
    (r'^events/(?P<year>\d{4})/(?P<month>[a-z]{3})/$','archive_month', dict(info_dict, template_name='archive/list.html')),
    (r'^events/(?P<year>)/$','archive_year', dict(info_dict, template_name='archive/list.html')),
    (r'^events/$','archive_index', dict(info_dict, template_name='archive/list.html')),
)

When I access /events/2010/may/12/this-is-a-slug/ I should get to the detail.html template, but instead I get a 404. What am I doing wrong?

And I'm using Django 1.1.2

+2  A: 

You forgot the backslashes in your regexes:

(r'events/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$'

Also you've (correctly) got the URL regex ending with a slash, so your URL should be /events/2010/may/12/this-is-a-slug/.

Daniel Roseman
I tried that, but It didn't work. It still shows a 404 at every url with variables.
x0rg
Are you *sure* you've got the regex correct now? Please post your updated version. And did you restart the server?
Daniel Roseman
updated the urlconf above
x0rg
A: 

Check the template_name once again.

zubinmehta
If the template doesn't exist, I should get a TemplateDoesNotExist-Exception, shouldn't I?
x0rg