【发布时间】:2016-09-06 00:56:22
【问题描述】:
我现在遇到的问题是:
未找到带有参数“(1,)”和关键字参数“{}”的“文档”的反向操作。尝试了 0 个模式:[]
当我尝试使用 HttpResponseRedirect 重定向到另一个视图时
这是我的 urls.py
url(r'^documentation/([0-9])/$', views.documents, name='documentation'),
这里是我的意见.py
def view1(request):
if request.method == 'POST':
profe = request.POST.get('value')
a = value.encode('ascii', 'ignore')
b = int(a)
return HttpResponseRedirect(reverse('documentation', args=(b,)))
else:
return render(request, "anhtml.html", info)
def documents(request,valor):
...something...
return render(request, "anotherhtml.html", ..something..)
谢谢
模板(anhtml.html)
...
<form method="POST" action="">
{% csrf_token %}
{% for p in ps %}
<tr>
<td><button id="boton1" button type="submit" name = "valor" value ="{{p.idp}}" class="btn btn-success btn-sm">{{p.nombre}} {{p.apellido}}</button>
</td>
<td>algo</a> </td>
</tr>
{%endfor%}
</form>
【问题讨论】:
-
出现错误时您尝试访问的 url 是什么?
-
主要想法是我被重定向到127.0.0.1:8000/documentation/1,但事实并非如此。如果将该网址直接粘贴到浏览器中,我将成功重定向。所以我现在确定正则表达式可以正常工作
-
什么动作触发了错误?显示您的模板代码可能会有所帮助。
-
刚刚添加了我的模板表单,实际上并没有比这复杂多少