views:

82

answers:

1

I type the following url in my browser:

http://localhost:8000/en/weblog/2010/aug/10/wie-baue-ich-ein-weblog/

an I get a "Page Not Found (404)" error, although the 10th entry

(r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(P?<slug>[-\w]+)/$', 'django.views.generic.date_based.object_detail', entry_info_dict),

in my URLConf should match.

The only difference is the prefix for the language, but this does not affect the other patterns, so why should it affect only this. (All urlpatterns are matched, except the above one)

My UrlConf looks like this:

urls.py

from django.conf.urls.defaults import *
from webpage import settings
import os 

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

from blog.models import Entry

urlpatterns = patterns('preview.views',
    (r'^admin/(.*)', admin.site.root),
    (r'^$', 'home'),
    (r'^about_me.html/', 'show_about_me'),
    (r'^study.html/', 'show_study'),
    (r'^profile.html/', 'show_profile'),
    (r'^blog.html/', 'show_blog'),
    (r'^contact.html/', 'show_contact'),
    (r'^impressum.html/', 'show_impressum'),
)

entry_info_dict = {
    'queryset': Entry.objects.all(),
    'date_field': 'pub_date',
    }

urlpatterns += patterns('',
    (r'^weblog/$', 'webpage.blog.views.entries_index'),
    (r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(P?<slug>[-\w]+)/$', 'django.views.generic.date_based.object_detail', entry_info_dict),
)

if settings.DEBUG:
    urlpatterns += patterns('', 
    (r'^static/(?P<path>.*)$', 'django.views.static.serve', { 'document_root' : os.path.join(settings.CURRENT_PATH, 'static') }),
)

What is the problem. I appreciate any help,

Best regards.

+1  A: 

Your pattern doesn't match the URL:

>>> import re
>>> pattern = r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(P?<slug>[-\w]+)/$'
>>> url = 'weblog/2010/aug/10/wie-baue-ich-ein-weblog/'
>>> print re.match(pattern,url)
None

It's because you have a typo in the pattern. You have P?<slug> and it should be ?P<slug>:

>>> pattern = r'^weblog/(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$'
>>> print re.match(pattern,url)
<_sre.SRE_Match object at 0x00B274F0>
Dave Webb
thank you very much. I need more accurate eyes :-)
Saeed