我已经看过文档 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)))),
我尝试访问以下 url。
'http://<mysite>.com/user/<someUsername>/profile/'
'http://<mysite>.com/abc/hello/'
最佳答案
试试这个 \w+
而不是 \S+
而不是 ''
而是用户 View 的路径:
profile_patterns = patterns('userapp.views',
url(r'^profile/$', profile),
url(r'^thoughts/$', thoughts),
)
urlpatterns = patterns('',
url(r'^/user/(?P<username>\w+)/', include(profile_patterns)),
)
关于Django:如何从 urls.py.. 中的同一文件添加其他 url 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26928103/