Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

python - How do I pass parameters via url in django?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...