简体   繁体   English

表单操作中的反向URL错误

[英]Reverse URL error in form action

I have this bit of HTML with a reverse URL: 我有一些带有反向URL的HTML:

<form role="form" method="post" action ="{% url 'add_location' %}">{% csrf_token %}

I am trying to have it work with this url pattern here: 我正在尝试使其与以下网址模式一起使用:

url(r'^location/add$', AddLocation.as_view(), name="add_location"),

But I am receiving the following error: 但是我收到以下错误:

Reverse for 'add_location' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

I think there is something fundamentally wrong happening here, but I can't seem to figure out what it is. 我认为这里根本发生了错误,但是我似乎无法弄清楚到底是什么。 I may not understand reverse urls correctly. 我可能无法正确理解反向网址。 I can provide more information if needed. 如果需要,我可以提供更多信息。

Okay so I figured it out, this wasn't extremely obvious. 好吧,我知道了,这不是很明显。

In whatever urls.py file that you are referring to the reverse in, you need to import reverse . 在您引用反向的任何urls.py文件中,都需要import reverse I thought I could get away with not importing it because I was using it in a template, but nope, you need to import it in that urls.py for those names to work in any templates. 我以为我可以不导入它,因为我在模板中使用它,但是不,您需要将其导入到urls.py中,以便这些名称在任何模板中都可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM