jinja2.exceptions.TemplateSyntaxError: expected token ':', got '}' in html

Question:

i’m trying to make an if into my code html with flask:

 {% if  {{ role }}  = 1  %}
            <div id="cabecera">
                <header class="py-3 mb-4 border-bottom">
                    <div class="container d-flex flex-wrap justify-content-center">
                    <a href="/home" class="d-flex align-items-center mb-3 mb-lg-0 me-lg-auto text-dark text-decoration-none">

i send {{ role }} from the login but when i execute the code, it say this:

enter image description here

i’m trying to control the view with permissions, if role is 1 show a div but if is other number, show a diferent div.

Asked By: juanjo

||

Answers:

Try this:

{% if role == 1 %}
    <div id="cabecera">
        <header class="py-3 mb-4 border-bottom">
            <div class="container d-flex flex-wrap justify-content-center">
                <a href="/home" class="d-flex align-items-center mb-3 mb-lg-0 me-lg-auto text-dark text-decoration-none">
(...)
{% endif %}
Answered By: Adrian Kurzeja

You don’t need the {{ }} to refer to variables inside Jinja statements. See here.

So provided you have passed a variable role to the template the following will work:

{% if role == 1 %}
        <div id="cabecera">
       etc...
{% endif %}
Answered By: ljdyer
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.