I’m using a template tag to load my header element into every page I have. In this header template I’m using the following code
{% if user.is_authenticated %}
<a class="btn btn-primary display-4" href="{% url 'home:profil' %}">{{ username }}</a>
{% else %}
<a class="btn btn-sm btn-black display-4" href="{% url "home:login" %}">Login</a>
{% endif %}
The implementation of this templatetag is working fine but the Backend doesnt seem to work.
The system doesnt check the authentication and doesnt see the {{username}} context allthough I passed it in the context of the view.
This is my register file of the tag:
from django import template
register = template.Library()
@register.inclusion_tag('partials/header2.html')
def header2(element):
return {'element': element, }
My view:
def profil_view(request):
packet = Account.objects.get(user=request.user)
username= packet.username
context = {
'username': username,
}
return render(request, 'profil.html', context)
and my template:
<head>{% load static %}
</head>
<body>
{% load header2_template %}
{% header2 element %}
</body>
Thanks for all your help!