I'm having trouble extracting a string from my URL. Here's what I've got.. it keeps 404ing.
urls.py:
urlpatterns = patterns('',
(r'^user/(?P<username>\w{0,50})/$', profile,),
)
开发者_开发知识库views.py:
def profile(request, username):
...
return ...
See anything obvious? Need more? Any help is appreciated.
I usually a /?$
at end of url pattern.
It is a common mistake and some browser add or not a trailing '/'.
Have you imported your views module at the top of your URL file?
from views import profile
urlpatterns = patterns('',
(r'^user/(?P<username>\w{0,50})/$', profile),
# also removed trailing comma after profile
)
# alternative
urlpatterns = patterns('',
(r'^user/(?P<username>\w{0,50})/$', 'views.profile'),
)
Have you got DEBUG = True in your settings file? That'll help find errors with a stacktrace that you should show us.
精彩评论