Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...