Here is the code in my base.html header
<script>
var auth_status = "{{ user.is_authenticated }}"
</script>
{% block scripts %} {% endblock %}
The rest of the scripts in my site are in the block scripts.
In a child template (within the script block and within script tags) I have this code,
if (auth_status) {
//something
}
The error at hand is auth_status is always True, when it should be on and off depending on if the user is logged in. Request_context is being passed to the template so that should not be the error.
Thanks
For what I see your
auth_statusvariable seems to be a string, not a boolean. A variable with a non-empty string on javascript will evaluate totrueon anifclause.Anyhow, something like
will not work because that will generate this HTML:
As Python’s True boolean is uppercased.
This should do the translation from Python to Javascript:
Check yesno docs here: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#yesno