John_p
John_p

Reputation: 13

how to use django authentication in "main" template

I've created a main HTML file where I have a template for all apps.

And in every other template file I am using :

{% extends "main.html" %}

To get the content.

But there are things I want to add to the main template but only if user is authenticated.

I know I can use

{% if user.is_authenticated %}

but it doesn't work in main.html file.

Do you know what am I doing wrong ? What should I do to solve this problem?

Thanks in advance,

Upvotes: 0

Views: 57

Answers (2)

doru
doru

Reputation: 9110

You can use

{% if request.user.is_authenticated %} 
    your code here 
{% endif %}

Upvotes: 0

user8586151
user8586151

Reputation:

1) Use {% debug %} template tag to understand User. https://docs.djangoproject.com/en/dev/ref/templates/builtins/#debug

Or 2) Using {% request.user.is_authenticated %} should get the authenticated user information from the Http Request.

Upvotes: 0

Related Questions