我使用python2.7.11和django 1.10.2。我创建了url并使用动态模板。在
网址.py
url(r'^suits-anarkali/', include([
url(r'^$', category_page, name="suits-anarkali"),
url(r'^(?P<slug>[\w-]+)/$', category_page, name="suits-anarkali"),
url(r'^(?P<slug>[\w-]+)/$', single_product, name='singleproduct'),
url(r'^(?P<slug>[\w-]+)/(?P<singleproduct_slug>[\w-]+)/$', singleproduct, name="singleproduct"),
])
),
这是我的url结构。如果我用slug调用category_页面,那么它工作正常,但是当我用slug调用single_product时,它会重定向到category page。 我试了很多次,但没用。那么如何在模板上管理url呢?在
产品.html
^{pr2}$
url在第一个匹配regexp的基础上工作,由于下面两行完全匹配相同的slug参数,所以当您使用slug调用url时,
category_page
首先匹配,因此django不会继续检查下一行。您需要对category_page
进行一些更改,使其与其他regexp不同。在read more on url tag
相关问题 更多 >
编程相关推荐