Search code examples
djangourlconf

Django URLconf: getting a 404 error


urls.py in project root

url(r'^people/',include('profiles.urls'))

profiles/urls.py

urlpatterns = patterns('profiles.views',
url(r'^me/$','home',name='profile_home'),
url(r'^(?P<user_name>[^/])/$','public_profile',name='user_public_profile'),
url(r'^signup/$','register_user',name='signup')
)

I am getting a 404 error and Django isn't able to find the Url's when I type for existing users, such as /people/alice while the other two patterns for the profile home and signup are working fine. Infact, this was working fine yesterday but not now, and I can't locate the problem.

The error message:

Django tried these URL patterns, in this order:
....
....    
^people/ ^me/$ [name='profile_home']
^people/ ^(?P<user_name>[^/])/$ [name='user_public_profile']
^people/ ^signup/$ [name='signup']

Solution

  • Regex pattern in the url is not correct

    url(r'^(?P<user_name>[^/])/$','public_profile',name='user_public_profile'),
    

    Change it to use [\w]+

    url(r'^(?P<user_name>[\w]+)/$','public_profile',name='user_public_profile'),