Django反面为'';带参数';(1)及"x27 ;;和关键字参数';{}';找不到

Django反面为'';带参数';(1)及"x27 ;;和关键字参数';{}';找不到,django,Django,我有一个由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\

我有一个由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()})
我的观点

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',
    ),
url(
r“^comment/(?P\d+/$”,
“pet.views.CommentCreator”,
名称='CommentCreator',
),
Html

{%if picture.image%}
{%endif%}

{注释%中c的%s} {%ifequal c.picture.id picture.id%}
{{c.body}}
{{c.created}}
{{c.user}} {%endifequal%} {%endfor%}



{%if图片%} {%csrf_令牌%} {{search}} {%endif%}
您的URL配置使用CommentCreator视图的关键字参数,将它们提供给
URL
,如下所示:

{% url 'CommentCreator' picture_id=picture.id %}

URL配置使用CommentCreator视图的关键字参数,将它们提供给
URL
,如下所示:

{% url 'CommentCreator' picture_id=picture.id %}

您需要在url标记中使用url名称:

{% url CommentCreator picture.id %}
就是这样,如果您使用的是django<1.3,那么url名称周围的单引号是不必要的。它在django 1.4中仍然可以工作,但它已被弃用,并且在django 1.5中被完全删除

为了将来的兼容性,如果django<1.5,则应使用此选项:

{% load url from future %}
{% url 'CommentCreator' picture.id %}
对于命名的捕获组URL,不必将URL参数作为关键字或参数传递,两者都可以工作(但了解顺序很重要,这就是为什么在URL标记中关键字参数更可取的原因):


您需要在url标记中使用url名称:

{% url CommentCreator picture.id %}
就是这样,如果您使用的是django<1.3,那么url名称周围的单引号是不必要的。它在django 1.4中仍然可以工作,但它已被弃用,并且在django 1.5中被完全删除

为了将来的兼容性,如果django<1.5,则应使用此选项:

{% load url from future %}
{% url 'CommentCreator' picture.id %}
对于命名的捕获组URL,不必将URL参数作为关键字或参数传递,两者都可以工作(但了解顺序很重要,这就是为什么在URL标记中关键字参数更可取的原因):


您将
而不是
放在url中

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

{%csrf_令牌%}
一定是

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

{%csrf_令牌%}

您将
而不是
放在url中

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

{%csrf_令牌%}
一定是

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

{%csrf_令牌%}

world.CommentCreator的参数“()”和关键字参数“{'picture\u id':1}”未找到,我得到了与此相反的错误。当前URL是否必须与Commentcreator URL匹配?已修复-您需要在其周围加引号,然后才能按名称引用视图。对于参数为“()”且关键字参数为“{picture\u id':1}”的“world.Commentcreator”,我发现此错误与此相反。当前URL是否必须与Commentcreator URL匹配?已修复-您需要在其周围加引号,然后才能按名称引用视图。请尝试引用并使用您给它的名称
{%URL'Commentcreator'picture.id%}
尝试引用并使用您给它的名称
{%URL'Commentcreator'picture.id%}