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:
- User opens
/admin/, enter correct credentials - Then user open some page, for example
/page/and there are “Add” and “Delete” buttons - User opens
/admin/and click “Log out” /page/-> there are no “Add” and “Delete” buttons
Django version 1.4
Joseph’s answer is fine for your simple case, but in reality neither
is_staffnoris_superuseris a perfect fit. Assuming your page is, say,/polls/(a list ofPollobjects, in an app calledpoll), you should test the specificpoll.change_pollandpoll.delete_pollpermissions.In a template:
Or in a view using
has_perm:Or in a view using a decorator:
You can assign these permissions directly to a user, to a group (and then put a user in that group) or by setting
is_superuser.