Reputation: 1926
In the django doc it is mentioned that {% include %} is deprecated since 1.11. Since I'm new to django, what is the alternative? Imagine you have a header of a page which is different if you are authenticated or not. I do not want to have both layouts in the header.html template...
Upvotes: 1
Views: 439
Reputation: 2570
to accomplish what you want I would suggest this:
{% if user.is_authenticated %}
<li><a href="{% url 'myprofile' %}"> My Profile</a></li>
{% else %}
<li><a href="{% url 'login' %}">Login</a></li>
<li><a href="{% url 'register' %}">Register</a></li>
<li><a class="fa fa-cog" href="{% url 'settings' %}" target="_blank"> Settings</a></li>
{% endif %}
So your header.html/base.html will know if the user is logged in and switches the attributes of the header.
Hope that helps :)
Upvotes: 1
Reputation: 32244
{% include %}
is not being deprecated
Any exceptions raised when rendering the included template will now be raised instead of being silenced
Deprecated since version 1.11: Silencing exceptions raised while rendering the {% include %} template tag is deprecated. In Django 2.1, the exception will be raised
Upvotes: 7