[Fixed]-How do I pass parameters via url in django?

23๐Ÿ‘

โœ…

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>
๐Ÿ‘คDric512

26๐Ÿ‘

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')
๐Ÿ‘คRexcirus

Leave a comment