0

django によって生成されたフォームがあり、フォームを含むオブジェクト ID を関数に返そうとしています。

このエラーを受け取りました。画像IDが有効なIDであり、現在の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()})

私のviews.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()})

私のURL.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 %}
4

3 に答える 3

0

URL.の代わりに入れます:

<form method = "post" action"{% url world.CommentCreator picture.id %}">
    {% csrf_token %}

それは違いない

<form method = "post" action"{% url world:CommentCreator picture.id %}">
    {% csrf_token %}
于 2013-03-30T06:31:57.003 に答える