Answer the question
In order to leave comments, you need to log in
Django. How to restrict access in a template?
At the moment, only unregistered users do not see the buttons, and those who are in the system see them, but they do not work for them, but how can I make sure that only the current user can see the buttons?
At the moment like this:
{% if user.is_authenticated %}
<a href="{% url 'listing_edit' listing.id %}" class="btn btn-secondary mb-4">
<h5><i class="fas fa-edit"> Редактировать</i></h5></a>
<a href="{% url 'listing_delete' listing.id %}" class="btn btn-danger mb-4">
<h5><i class="fa fa-trash-alt"> Удалить</i></h5></a>
{% endif %}
{% if user.is_authenticated and request.user == 'POST' %}
Answer the question
In order to leave comments, you need to log in
{% if listing.realtor == user %}
<a href="{% url 'listing_edit' listing.id %}" class="btn btn-secondary mb-4">
<h5><i class="fas fa-edit"> Редактировать</i></h5>
</a>
<a href="{% url 'listing_delete' listing.id %}" class="btn btn-danger mb-4">
<h5><i class="fa fa-trash-alt"> Удалить</i></h5>
</a>
{% endif %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question