简体   繁体   中英

Reverse URL error in form action

I have this bit of HTML with a reverse URL:

<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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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