我目前的urls.py
urlpatterns = patterns('hunt.views',
url(r'^$', views.top100, name='top100'),
url(r'^top100/(?P<slug>.+)/$', views.dj, name='dj'),
url(r'^explore/$', views.explore, name='explore'),
url(r'^explore/(?P<slug>.+)/$', views.explore_dj, name='explore_dj'),
url(r'^monthlytop/$', views.monthlytop10, name='monthlytop10'),
url(r'^trending/$', views.trending, name='trending'),
url(r'^contact/$', views.contact, name='contact'),
url(r'^thanks/$', views.thanks, name='thanks'),
url(r'^faq/$', views.faq, name='faq'),
url(r'^search/(?P<slug>.+)$', views.search, name='search'),
url(r'^sitemap\.xml$', direct_to_template,
{'template': 'sitemap.xml'}),
url(dajaxice_config.dajaxice_url, include('dajaxice.urls')),
)
我想将我的网址从/top100/slug
和/explore/slug
更改为/slug
我这是对我的urls.py
urlpatterns = patterns('hunt.views',
url(r'^$', views.top100, name='top100'),
url(r'^(?P<slug>.+)/$', views.dj, name='dj'),
url(r'^explore/$', views.explore, name='explore'),
url(r'^(?P<slug>.+)/$', views.explore_dj, name='explore_dj'),
url(r'^monthlytop/$', views.monthlytop10, name='monthlytop10'),
url(r'^trending/$', views.trending, name='trending'),
url(r'^contact/$', views.contact, name='contact'),
url(r'^thanks/$', views.thanks, name='thanks'),
url(r'^faq/$', views.faq, name='faq'),
url(r'^search/(?P<slug>.+)$', views.search, name='search'),
url(r'^sitemap\.xml$', direct_to_template,
{'template': 'sitemap.xml'}),
url(dajaxice_config.dajaxice_url, include('dajaxice.urls')),
)
我可以访问该页面上的目标网页和所有slu ..但是,如果我尝试访问explore
或monthlytop
或任何其他网页,我会收到DoesNotExist
错误。
答案 0 :(得分:0)
字符串“explore”匹配slug的正则表达式,因此它将转到该视图。你可以把第一个单词视图放在第一个单词之前,所以它们会先匹配。
但是你仍然有问题,因为dj和explore_dj的正则表达式完全相同。你需要有一些方法来区分它们。