player.mdl
player.mdl

Reputation: 113

Django only matches urls with an app prefix/identifier

I'm having a problem with django's URL system. I'm using Django 3. I have the following in my project's 'urls.py'

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

and this in the 'urls.py' of a django app in the project, called 'siteadmin':

urlpatterns = patterns('',
    url(r'^$', views.home, name='home'),
    url(r'^register/$', views.register, name='register'),
    url(r'^login/$', views.user_login, name='login'),

    #...trimmed
)

With this setup, the following happens:

  1. http://localhost/ => works perfectly, renders the 'home' view
  2. http://localhost/register/ => breaks. (gives 404 and django's standard "The current URL, register, didn't match any of these.")

However, when I change the project's 'urls.py' to include the following:

urlpatterns = patterns('',
    url(r'^app/', include('siteadmin.urls')),
)

And include /app/ in 1. and 2., both urls work perfectly. That is to say:

  1. localhost/app/ => works perfectly
  2. localhost/app/register => works perfectly.

What am I missing? Why does #2 break in the first case, but not the second?

Upvotes: 0

Views: 207

Answers (1)

catavaran
catavaran

Reputation: 45575

Remove the dollar sign from the regex in the project urls.py:

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

Upvotes: 1

Related Questions