Reputation:
I have this code in index.html
:
{% url 'cronjobs:remove-job' as remove_job_url %}
And I want to use it further down in the same HTML file multiple times, e.g.:
<a href="{{ remove_job_url }}">Remove job</a>
According to this answer, I think I got everything right. However, the variable remove_job_url
is null. Nothing is printed to the anchor tag.
I have loaded the Jinja2 into my settings.py -> TEMPLATES
as described in the documentation, yet it does not seem to work. Any ideas what might be wrong?
(this also happens when I use the {% trans ... as trans_var %}
tag, the trans_var
is again - empty)
Upvotes: 1
Views: 603
Reputation: 1121982
You are trying to use Django template syntax in a Jinja2 template. The template syntax is related, but no the same. You need to use Jinja2 assignment syntax instead.
{% set remove_job_url = url('cronjobs:remove-job') %}
Note the url()
call. See the Url reversing section of the Django-jinja integration documentation.
Upvotes: 2