[Fixed]-Tag inside tag in django template


The simplest solution would be:

{% url 'settings' var1 var2 as action_url %}

{% include "default_form.html" with action=action_url %}


You cannot do this:

{% include "default_form.html" with action="{% url 'settings' var1 var2 %}" %}

You can only use once the {% ... %} and then inside that you can use tags, variables etc… for example if you have inside a variable called url_with_vars you should do this:

{% url 'settings' var1 var2 as url_with_vars %}

{% include "default_form.html" with action=url_with_vars %}

tip: Inside the {% .... %} you can call a django variable without using the {{..}} meaning that in the template to show a django variable you use {{variable}} but inside {% whatever_action ... %} you do not do like {% whatever_action {{variable}} %} the correct way would be {% whatever_action variable %}

But then you will realize that there is other problems to assign that url value with vars to a variable.

If you are trying to add action="{% url 'settings' var1 var2 %}" %} to the form, I strongly recommend you to do something like:

<form action="{% url 'settings' var1 var2 %}">
    {% include "default_form.html" %}

What I’m trying to say in this part is that it will be a lot easier for you to have the form declaration in the template, and the values inside the form in the subtemplate, because it will be too hard to do what you’re trying to do


for visitors using {{}} inside {%%} to load static files:

<link rel="stylesheet" type="text/css" href="{% static 'css/theme/{{ theme }}.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'css/theme/' %}{{theme}}.css" />

Leave a comment