Ayaan
Ayaan

Reputation: 167

Pass in variable to tag django

is there a way to pass in a variable in a tag in django templating?

For example, <a href="{% url '{{ url_path }}' %}">Click here</a>, as you can see, I want to pass the url_path variable into the url tag, but when I do this, django treats {{ url_path }} as the string itself, not the variable url_path. Is there a way to pass in that variable in the url tag? Thanks in advance!

Upvotes: 1

Views: 51

Answers (2)

gha7all
gha7all

Reputation: 65

Don't use quotes, by using quotes Django thinks you want to pass the template page directly.

Upvotes: 0

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476614

You simply pass a variable without using quotes, and without using curly brackets ({{ … }}):

<a href="{% url url_path %}">Click here</a>

Upvotes: 1

Related Questions