开发者

Variables and Django URLConf

开发者 https://www.devze.com 2023-01-31 13:51 出处:网络
I\'m having trouble extracting a string from my URL. Here\'s what I\'ve got.. it keeps 404ing. urls.py:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号