Pergunta

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']
Foi útil?

Solução 2

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'),

Outras dicas

Your regex only allows for a single character to match the username. You need to add a +:

r'^(?P<user_name>[^/]+)/$'
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top