我无法从我的 URL 中提取字符串。这就是我所拥有的......它一直在404ing。
网址.py:
urlpatterns = patterns('',
(r'^user/(?P<username>\w{0,50})/$', profile,),
)
视图.py:
def profile(request, username):
...
return ...
看到什么明显的东西了吗?需要更多?任何帮助表示赞赏。
我通常/?$
在 url 模式的末尾。
这是一个常见的错误,一些浏览器添加或不添加尾随'/'。
您是否在 URL 文件的顶部导入了视图模块?
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'),
)
您的设置文件中有 DEBUG = True 吗?这将有助于发现您应该向我们展示的堆栈跟踪错误。