Reputation:
As I said in the title, what would be the correct syntax to change the href of a link according to the current url the user is on?
I tried this, but it doesn't work.
{% if url == '' %} href='/cookies' {% else %} href='' {% endif %}
What would be the correct syntax to do this?
Upvotes: 0
Views: 332
Reputation: 161
At Django 1.9 and above can use something like this
href='{% if not request.path %}/cookies{% endif %}'
Upvotes: 1
Reputation: 1848
You can check the current url with
href="{% if request.path == '' %}/cookies{% endif %}"
Upvotes: 0