我已经看过文档here,我正在尝试做同样的事情,但它不起作用。它与网址不匹配。
这是我的urls.py
profile_patterns = patterns('',
url(r'^profile/$', views.profile),
url(r'^thoughts/$', views.thoughts),
)
urlpatterns = patterns('',
url(r'^/user/(?P<username>\S+)/', include(profile_patterns)),
# I also tried to do it this way.. But it isn't working.
url(r'^abc/', include(patterns('',
url(r'^hello/$', views.profile)))),
我尝试访问以下网址。
'http://<mysite>.com/user/<someUsername>/profile/'
'http://<mysite>.com/abc/hello/'
答案 0 :(得分:2)
试试这个\w+
代替\S+
而不是''
,但是请看用户观看的路径:
profile_patterns = patterns('userapp.views',
url(r'^profile/$', profile),
url(r'^thoughts/$', thoughts),
)
urlpatterns = patterns('',
url(r'^/user/(?P<username>\w+)/', include(profile_patterns)),
)