[Answer]-Django url wrong

1👍

Your URL pattern is missing parenthesis to show that you want to capture the offset from the URL. Try changing it to the following:

(r'^time/plus/(\d{1,2})/$', hours_ahead),

Often, people prefer to use named groups in their URL patterns. In your case, the URL pattern would change to:

(r'^time/plus/(?P<offset>\d{1,2})/$', hours_ahead),

0👍

So rather than importing the views module for that app and the given handler’s you’re supposed to supply a string I believe, so this should work for your urls.py

from django.conf.urls.defaults import *
from mysite.views import current_datetime, hours_ahead

urlpatterns = patterns('',
     (r'^time/$', 'mysite.views.current_datetime'),
     (r'^time/plus/\d{1,2}/$', 'mysite.views.hours_ahead'),

)

Leave a comment