Python product_list()获取了意外的关键字参数';产品标识';
我在product_id的标题中得到了这条消息,但我认为我在product_form()及其路径上都正确地使用了它。有人能帮忙吗 我本来想给变量id命名的,但在我测试它之前,pylint遇到了问题,所以我改为product_id views.pyPython product_list()获取了意外的关键字参数';产品标识';,python,django,Python,Django,我在product_id的标题中得到了这条消息,但我认为我在product_form()及其路径上都正确地使用了它。有人能帮忙吗 我本来想给变量id命名的,但在我测试它之前,pylint遇到了问题,所以我改为product_id views.py def product_form(request, product_id=0): """Formulário de Cadastro de Produtos""" if req
def product_form(request, product_id=0):
"""Formulário de Cadastro de Produtos"""
if request.method == "GET":
if product_id==0:
form = ProductForm()
else:
product = Product.objects.get(pk=product_id)
form = ProductForm(instance=product)
return render(request, "product_register/product_form.html", {'form': form})
else:
form = ProductForm(request.POST)
if form.is_valid():
form.save()
return redirect('/product')
url.py
urlpatterns = [
path('', views.product_list, name='product_list'),
path('product-form/', views.product_form, name='product_insert'),
path('product-form/<int:product_id>/', views.product_list, name='product_update'),
path('category-form/', views.category_form, name='category_insert')
]
urlpatterns=[
路径(“”,views.product_list,name='product_list'),
路径('product-form/',views.product\u form,name='product\u insert'),
路径('product-form/',views.product_list,name='product_update'),
路径('category-form/',views.category\u form,name='category\u insert')
]
html
{%extensed“product\u register/base.html”%}
{%block content%}
诺姆
描述
普雷西奥
范畴
{product_list%}中产品的%
{{product.name}
{{product.description}}
{{product.price}}
{product.category.all%中类别的%
{{category.name}},
{%endfor%}
{%endfor%}
{%endblock内容%}
由于错误状态为产品列表,您似乎选择了错误的视图,但您发布了产品表单谢谢,就是这样。当我调用视图时,URL中的路径是views.product\u列表,应该是views.product\u表单。
{% extends "product_register/base.html" %}
{% block content %}
<table class="table table-borderless">
<thead class="border-bottom font-weight-bold">
<tr>
<td> Nome </td>
<td> Descrição </td>
<td> Preço </td>
<td> Categoria </td>
<td></td>
</tr>
</thead>
<tbody>
{% for product in product_list %}
<tr>
<td> {{product.name}} </td>
<td> {{product.description}} </td>
<td> {{product.price}} </td>
<td>
{% for category in product.category.all %}
{{category.name}},
{% endfor %}
</td>
<td>
<a href="{% url 'product_update' product.id %}" class="btn text-secondary px-0">
<i class="far fa-edit fa-lg"></i>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock content %}