如何使用两个参数正确地将urls.py中的edit_product.html行引用到Edit_Product?
我尝试查找示例,但找不到任何示例。
这是我收到的错误:
找不到带有参数'('eiffel',)'的'Edit_Product'的反向。尝试了1种模式:['shop / edit_product /(?P [-a-zA-Z0-9 _] +)/(?P [-a-zA-Z0-9 _] +)/ $'] >
urls.py
from django.urls import path
from . import views
app_name='shop'
urlpatterns = [
path('create_product/', views.CreateProduct, name='Create_Product'),
path('edit_product/<slug:c_slug>/<slug:product_slug>/', views.EditProduct, name='Edit_Product'),
path('', views.allProdCat, name='allProdCat'),
path('<slug:c_slug>/', views.allProdCat, name='products_by_category'),
path('<slug:c_slug>/<slug:product_slug>/', views.ProdCatDetail, name='ProdCatDetail'),
]
edit_product.html
<td><a href="{% url 'shop:Edit_Product' category.slug | product.slug %}">{{ product.name }}</a></td>
答案 0 :(得分:1)
您不需要|只需将空格隔开
<a href="{% url 'shop:Edit_Product' category.slug product.slug %}">