'How to hide some fields if user not logged in Django?
I want to hide some fileds from not logged users. For example I have model account with fields:
name, surname, address, tel,
and I want to hide address and tel fields if user is not logged in. I found some examples, but it hide whole model, not just a part I need.
Solution 1:[1]
You can do it in in templates by using built-in conditional tags:
{% comment %} Visible to everyone {% endcomment %}
{{ object.name }} {{ object.surname }}
{% if request.user.is_authenticated %}
{% comment %} Visible to logged in users only {% endcomment %}
{{ object.address }}
{{ object.tel }}
{% endif %}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | M Burak |
