【发布时间】:2014-05-21 21:14:28
【问题描述】:
我正在尝试将此表单提交给我的视图:
在 pcq_select.html 中
<form action="{% url 'pcq_list' product_id %}" method="POST">{% csrf_token %}
<label>Select the Product:
<select name="product_id">
{% for entry in products %}
<option value="{{ entry.id }}">{{ entry.productname }}</option>
{% endfor %}
</select>
<input type="submit" value="Go"></label>
</form>
在views.py中
def pcq_select(request, template_name='maps/pcq/pcq_select.html'):
product = Product.objects.all()
return render(request, template_name, {'products': product})
def pcq_list(request, product_id="1"):
pcq = Pcq.objects.filter(product_id=product_id)
data = {}
data['object_list'] = pcq
return render(request, 'maps/pcq/pcq_list.html', data)
在 urls.py 中
url(r'^pcq/list/(\d+)/$', views.pcq_list, name='pcq_list'),
我收到以下错误:
异常类型:NoReverseMatch 异常值:“pcq_list”的反向参数“(”,)”和关键字参数“{}”未找到。尝试了 1 种模式:['maps/pcq/list/(\d+)/$']
模板渲染时出错
在模板 E:\SampleSite\templates\maps\pcq\pcq_select.html 中,第 1 行出错
但是,当我用数字替换操作 url 中的 product_id 时(示例 1),整个事情都很好。请帮忙。
【问题讨论】:
标签: django