The Below code:
{% ifequal username AnonymousUser %}
<p>Welcome</p>
{% else %}
<p> Welcome {{ username }}. Thanks for logging in.</p>
{% endifequal %}
Shows This:
Welcome AnonymousUser. Thanks for logging in.
What the? I'm more than a little miffed. I'm pretty sure i don't need to supply extra code for you to understand my problem.
I dont think it's an ifequal problem. I have a pretty good handle on that.
Username comes from:
username = request.user
Does this mean username at this point in the code is not a string. Do i have to convert it to a string.
You need to compare to a string. Use this:
Here's the Django documentation on checking equality with
ifequal
.Ensure your variable is a string, and one that's trimmed of leading and trailing whitespaces as well.