Categories
Python Answers

How to add URL parameters to Python Django template url tag?

Spread the love

To add URL parameters to Python Django template url tag, we can add them after the URL name.

For instance, we write

url(r'^panel/person/(?P<person_id>[0-9]+)$', 'apps.panel.views.person_form', name='panel_person_form'),

to add a URL with url.

And then we add the parameter by writing

{% url 'panel_person_form' person_id=item.id %}

to add the person_id parameter after the URL name.

We separate multiple parameters with spaces.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *