views:

38

answers:

2

I'm doing something stupid, and I'm not sure what it is. I have a the following urls.py in the root of my django project:

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

urlpatterns = patterns('',
    (r'^$', include('preview_signup.urls')),
)

In my preview_signup module (django app) I have the following urls.py file:

from django.conf.urls.defaults import *

urlpatterns = patterns('django.views.generic.simple',
    (r'^thanks/$', 'direct_to_template', {'template': 'thankyou.html'})
)

The urls.py above doesn't work when I go to http://localhost:8000/thanks/. But if it's changed to this:

from django.conf.urls.defaults import *

urlpatterns = patterns('django.views.generic.simple',
    (r'^$', 'direct_to_template', {'template': 'thankyou.html'})
)

And I go to http://localhost:8000/ it works fine.

What am I doing wrong?

+2  A: 

This code should work:

urlpatterns = patterns('', (r'^', include('preview_signup.urls')), )

$ (end of line) just removed.

Vadim Shender
DOH! Yup, that works. Thanks a million :) (I have to wait 8 minutes until I can accept)
Eric Palakovich Carr
+1  A: 

When something goes wrong (or even if it doesn't), thoroughly read the django docs. Here's an excerpt from the aforementioned link:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^weblog/',        include('django_website.apps.blog.urls.blog')),
    (r'^documentation/', include('django_website.apps.docs.urls.docs')),
    (r'^comments/',      include('django.contrib.comments.urls')),
)

Note that the regular expressions in this example don't have a $ (end-of-string match character) but do include a trailing slash. Whenever Django encounters include(), it chops off whatever part of the URL matched up to that point and sends the remaining string to the included URLconf for further processing.

sdolan
Agreed, but I did read through the docs. It's just easy to skim past those parts, especially when at first glance they look like the same code you're using. I must have read past that particular passage a few times while looking for an answer.
Eric Palakovich Carr