F
F
From Prog2022-04-21 14:23:19
Django
From Prog, 2022-04-21 14:23:19

How to change website directory using Jinja2?

I need to make it so that if a person is not authorized on the site, then he is redirected to another page, how to do this in an HTML file?

The code:

{% if user.is_authenticated %}
    <span id='name_of_user'>{{ user.username }}</span>
{% else %}
    ЗДЕСЬ НАДО СДЕЛАТЬ ПЕРЕНАПРАВЛЕНИЕ В ДРУГУЮ ДИРЕКТОРИЮ САЙТА
{% endif %}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Nesterov, 2022-04-21
@FromProg

Why such complications?
Isn't it more logical to do it at the server level?
In addition, believe me, if a moderately knowledgeable hacker wants to go to a page that checks authorization using templates, he will go there.

S
Sergey Gornostaev, 2022-04-21
@sergey-gornostaev

The template should be responsible only for the presentation, there is no place for logic in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question