使用django 2.2遇到此错误,这是我的代码
app_name ='产品'
urlpatterns = [
url(r'^$', product_list, name='product-list'),
url(r'^(?P<slug>.*)/$',single, name="single_product"),
url(r'^category/(?P<slug>.*)/$',category_single,name="category")
]
def get_absolute_url(self,):
return HttpResponseRedirect(reverse('single_product',args=[self.slug]))
<h3>{{ product }}</h3>
<p>{{ product.description }}</p>
<p>{{ product.get_price }}</p>
<p>
<a href ="{% url 'products:single_product' %}" class = "btn btn-primary" role = "button">
View Product
</a>
答案 0 :(得分:2)
您没有在url中传递该标签,而是为您的模式提供了一个参数。
因此更改html
<a href ="{% url 'products:single_product' product.slug %}" class = "btn btn-primary" role = "button">
View Product
</a>