[Answer]-How to deactivate buttons in Django applications where all buttons are localized in a single base.html file?

1๐Ÿ‘

{% block sidebar %}
  <p>
 {% if user.is_authenticated %}
 <a href = "/accounts/login/"><button>Login</button></a>
 <a href = "/accounts/profile/"><button>User Profile</button></a>
 <a href = "/admin/"> <button>Site Administration</button></a>
 {% else %}
 <a href = "/accounts/register/"><button>Account Registrration</button></a>
 {% endif %}
 </p>
{% endblock %}

To hide it completely, which in my humble opinion is better than having it be visible and disabled ๐Ÿ™‚

BTW. your code as pasted is missing the closing </a> tags

0๐Ÿ‘

Just use

{% if user.is_authenticated %}
  <a><button disabled>Login</button> </a>
{% else %}
  <a href = "/accounts/login/"><button>Login</button> </a>
{% endif %}

in your base.html. Even if there are derived templates, the logged in status will be available to them and this would work as expected.

๐Ÿ‘คarocks

Leave a comment