A
A
Anton Styazhyakin2021-01-25 20:12:31
Flask
Anton Styazhyakin, 2021-01-25 20:12:31

How to make conditions based on a specific URL in Flask?

I have a block with only two lines

<a class="nav-link" href="{{ url_for('user.signup') }}">У меня нет аккаунта</a>
<a class="nav-link" href="{{ url_for('user.signin') }}">У меня есть аккаунт</a>

I want that if the user is located at site/user/signup, then the second line would be displayed to him, and if the site is/user/signin, then the first line, respectively. How can this be done? What can you do with conditions in request.path?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wispik, 2021-01-26
@Wispik

{% if request.path == '/user/signup' %}
    <a class="nav-link" href="{{ url_for('user.signin') }}">У меня есть аккаунт</a>
{% elif request.path == '/user/signin' %}
    <a class="nav-link" href="{{ url_for('user.signup') }}">У меня нет аккаунта</a>
{% endif %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question