Jinja2 Flask If Else Statement

You cannot make a {% block %} conditional; once you use the tag, the block is always going to be filled in.

Put your conditional inside the block instead, and use super() to instruct Jinja to use the original contents of the block as defined in the template:

{% extends "base.html" %}
{% block content %}
    {% if condition %}
        <div>blah blah blah blah</div>
    {% else %}
        {{ super() }}
    {% endif %}
{% endblock content %}

Software Engineer | Ethical Hacker & Cybersecurity...

Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.