S
S
Stanislav Konovalov2019-03-10 20:54:50
Django
Stanislav Konovalov, 2019-03-10 20:54:50

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 %}

I wrote, for example, like this:
{% if user.is_authenticated and request.user == 'POST' %}

But then the current button does not see either.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-03-10
@stas_workout

{% 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 question

Ask a Question

731 491 924 answers to any question