Menu

Beanzilla

Never give up, Never surrender

Python Django

<h1>Django</h1>
{% if user.authenticated %}
<p>Hello, {{ user.username }} <a href="{% url 'logout' %}">Logout</a>.</p>
{% else %}
<p>Hello, Stranger <a href="{% url 'login' %}">Login</a>.</p>
{% endif %}

Lines 1, 3, and 5 are standard HTML...

Except Lines 3 and 5 also have Django tags. (In this case redirect the user to the logout page and a guest to the login page.)

But all that is changed by Lines 2, 4, and 6. (As you can probably guess, if a user is logged in then it shows their name and the logout link, else it gives the login link.)

But of course you can do more... this is just to show Django's Template features.

Written by Bzy on Thursday June 6, 2019

Permalink -

« Weather 10: Radar