moidol moidol - 7 months ago 58
Javascript Question

Using Django, how can I detect an admin in my javascript?

I have functions in my JavaScript which I would not like to be available to normal users, and only to admins/staff. Ideally I can create a boolean variable which is true/false depending on whether the request user is staff or not, but how would I set this boolean?

Note: I'm not trying to disable them for security, but only for user experience.

Answer Source

You can try use yesno filter inside js, for example:

var is_staff = {{ request.user.is_staff|yesno:"true,false" }}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download