我有 django 生成的表单,我正在尝试将带有表单的对象 id 返回给函数。
我收到此错误。我似乎无法弄清楚为什么它不起作用,因为图片 id 是有效的 id,并且 URL 的正则表达式应该捕获它并将其返回给我的函数,除非当前 URL 必须匹配,因为我当前的 URL页面是 1:8000/comment/1/
Reverse for 'world.CommentCreator' with arguments '(1,)' and keyword arguments '{}' not found.
File "C:\o\17\mysite\pet\views.py" in CommentCreator
269. return render(request,'commentcreator.html', {'comment':comment,'picture':p,'search':CommentsForm()})
我的观点.py
def CommentCreator(request,picture_id):
p = Picture.objects.get(pk=picture_id)
comment = Comment.objects.filter(picture=p)
return render(request,'commentcreator.html', {'comment':comment,'picture':p,'search':CommentsForm()})
我的网址.py
url(
r'^comment/(?P<picture_id>\d+)/$',
'pet.views.CommentCreator',
name = 'CommentCreator',
),
html
{% if picture.image %}
{% endif %}
<ul>
<br><img src="{{ picture.image.url }}">
</ul>
{% for c in comment %}
{% ifequal c.picture.id picture.id %}
<br>{{ c.body }}</li>
<br>{{ c.created}}</li>
<br>{{ c.user}}</li>
{% endifequal %}
{% endfor %}
<br><br><br><br>
{% if picture %}
<form method = "post" action"{% url world.CommentCreator picture.id %}">{% csrf_token %}
{{search}}
<input type ="submit" value="Search "/>
</form>
{% endif %}