Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Flask if block: jinja2.exceptions.TemplateSyntaxError: unexpected '%'


                <div class="mb-3">
                    {{ form.ism.label(class="form-label") }}
                    
                    {{% if form.ism.errors %}}
                        {{ form.ism(class="form-control form-control-lg is-invalid") }}
                        <div class="invalid-feedback">
                            {% for error in form.ism.errors %}
                                <span>{{ error }}</span>
                            {% endfor %}
                        </div>
                    {% else %}
                        {{ form.ism(class="form-control form-control-lg") }}    
                    {{% endif %}}                      
                </div>      

jinja2.exceptions.TemplateSyntaxError: unexpected ‘%’

How can i solute this error?

I looked code again and again but i could not find the what is real problem.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Debugger saying error at 4. line
This code:
{{% if form.ism.errors %}}

>Solution :

The syntax for variables is {{ myVar }}

The syntax for expressions such as if and for is {% if ... %}

Thus, instead of writing {{% %}}, you should go with {% %} which is the appropriate syntax.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading