变量和 Django URLConf
我无法从 URL 中提取字符串。这就是我所得到的..它不断出现 404ing。
urls.py:views.py
urlpatterns = patterns('',
(r'^user/(?P<username>\w{0,50})/$', profile,),
)
:
def profile(request, username):
...
return ...
看到任何明显的东西了吗?需要更多吗?任何帮助表示赞赏。
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})/
views.py:
def profile(request, username):
...
return ...
See anything obvious? Need more? Any help is appreciated.
, profile,),
)
views.py:
See anything obvious? Need more? Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通常在 url 模式末尾添加
/?$
。这是一个常见的错误,有些浏览器添加或不添加尾随“/”。
I usually a
/?$
at end of url pattern.It is a common mistake and some browser add or not a trailing '/'.
您是否已在 URL 文件顶部导入了视图模块?
您的设置文件中是否有 DEBUG = True ?这将有助于通过您应该向我们展示的堆栈跟踪来查找错误。
Have you imported your views module at the top of your URL file?
Have you got DEBUG = True in your settings file? That'll help find errors with a stacktrace that you should show us.