[Django]-Django: Refer to an url name in a template and passing parameter

3👍

Simply, you don’t.

You either adjust your url to have two capture groups (which would also require a slight change to the view)

url(r'(?P<first_name>\w+)_(?P<last_name>\w+)/$', view_name, name='url_name')
{% url 'urlname' user.firstname user.lastname %}

Or you just find a different url that suffices.

👤Sayse

0👍

Please have a look at this thread. The good answer for you, assuming you’re using posititionnal arguments :

<a href="{% url 'urlname' parameter=user.firstname_user.lastname %}">The link</a>

Assuming your url conf is like so :

url(r'^urlname/(?P<parameter>(catching regexp))$',...)

Leave a comment