Reputation: 4411
I am trying to pass a parameter to my view, but I keep getting this error:
NoReverseMatch at /pay/how
Reverse for 'pay_summary' with arguments '(False,)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['pay/summary/$']
/pay/how
is the current view that I'm at. (that is the current template that that view is returning).
urls.py
url(r'^pay/summary/$', views.pay_summary, name='pay_summary')
views.py
def pay_summary(req, option):
if option:
#do something
else:
#do something else
....
template
<a href="{% url 'pay_summary' False %}">my link</a>
EDIT
I want the view should accept a POST request, not GET.
Upvotes: 14
Views: 90925
Reputation: 2887
To add to the accepted answer, in Django 2.0 the url syntax has changed:
path('<int:key_id>/', views.myview, name='myname')
Or with regular expressions:
re_path(r'^(?P<key_id>[0-9])/$', views.myview, name='myname')
Upvotes: 26
Reputation: 3729
You need to define a variable on the url. For example:
url(r'^pay/summary/(?P<value>\d+)/$', views.pay_summary, name='pay_summary')),
In this case you would be able to call pay/summary/0
It could be a string true/false by replacing \d+
to \s+
, but you would need to interpret the string, which is not the best.
You can then use:
<a href="{% url 'pay_summary' value=0 %}">my link</a>
Upvotes: 23