How can I detect, from views or template file, if my admin user is logged in or not? For example, use case for my site:
/admin/, enter correct credentials/page/ and there are "Add" and "Delete" buttons/admin/ and click "Log out"/page/ -> there are no "Add" and "Delete" buttonsDjango version 1.4
In templates:
{% if user.is_superuser %} <p>Hello, admin.</p> {% else %} <p>Hello, ordinary visitor.</p> {% endif %} In views:
if request.user.is_superuser: # Hello, admin. else: # Hello, ordinary visitor. Depending on your needs, is_staff might be a better fit than is_superuser. You can read about the difference here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With