[Answer]-Cannot get Django App to serve correct URL

1👍

As I said, django is running index() for both URLs.

Given your code, when you go to /testweb, Django matches the second line from testweb/urls.py and then the first line in foo/urls.py. Try /testweb/testweb. You’ll see that this runs (lambda x: HttpResponse("testweb!")).

That’s happening because you’re pointing both URLs to include('foo.urls'). Going to /testweb/ matches the second URL in testweb/urls.py, and which includes foo.urls and looks for a match there. Since you’ve got nothing in your URL after /testweb/, the resolver then hits the first URL in foo.urls, which is for the index lambda. include a different URLConf or just reference the views directly, like:

# testweb/urls.py
urlpatterns = patterns('',
    url(r'^$', (lambda x: HttpResponse("index!")), name='index'),
    url(r'^testweb/', (lambda x: HttpResponse("testweb!")), name='testweb'),
)

and you’ll get your expected results.

Leave a comment