简体   繁体   中英

django - NoReverseMatch form

I have a little problem with my app.

#urls
url(r'generator/$', SelectView.as_view()),
    name="select"),
url(r'choices/(?P<types>\w+)$', ChoicesView.as_view()),
    name="choice"),

#views
class SelectView(FormView):
    template_name = "generator/show_choices.html"
    form_class = ChoiceForm
    def form_valid(self, form):
        types = form.cleaned_data["type"]
        return redirect(reverse_lazy(
            "choice",
            kwargs={"types": types}))

#template
<form method="POST" action="{% url 'report_filtering' reporttype %}">
{% csrf_token %}
    {{ form }}
    <input type="submit" value="Send message" />
</form>

And I get error: Reverse for 'choice' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'pl/generator/choice/(?P\\w+)$'], when I open generator/ page.

Any ideas?

Notice that it is attempting to use choice in the url, instead of choices , as you have it set to do in your urls.py .

Try correcting your syntax and see if it works:

url(r'^generator/$', SelectView.as_view(),
    name="select")),
url(r'^choices/(?P<types>\w+)/$', ChoicesView.as_view(),
    name="choice")),

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