ImportError: cannot import name ‘Markup’ from ‘jinja2’

As the import error comes from flask File “/usr/local/lib/python3.7/site-packages/flask/__init__.py I tried to create a new Flask application using Flask==1.0.2 and found that the error comes from this version of Flask when it used with Jinja2>=2.10.1. But when you remove Flask==1.0.2 and install Flask==2.0.3, everything works fine. pip uninstall Flask Jinja2 pip install Flask Jinja2 Dependencies … Read more

What dashes mean in jinja templates?

Turns out that + and – are there for whitespace control purpose. You can manually disable the lstrip_blocks behavior by putting a plus sign (+) at the start of a block […] You can also strip whitespace in templates by hand. If you put an minus sign (-) to the start or end of an … Read more

Rendering a dictionary in Jinja2

Your url_list should look like this: url_list = [{‘target’: ‘http://10.58.48.103:5000/’, ‘clicks’: ‘1’}, {‘target’: ‘http://slash.org’, ‘clicks’: ‘4’}, {‘target’: ‘http://10.58.48.58:5000/’, ‘clicks’: ‘1’}, {‘target’: ‘http://de.com/a’, ‘clicks’: ‘0’}] Then using: <li>{{ item[“target”] }}</li> in your template will work. Edit 1: Your template think you’re passing a list in, so are you sure you’re passing in your original dict and … Read more

Multiple level template inheritance in Jinja2?

One of the best way to achieve multiple level of templating using jinja2 is to use ‘include’ let say you have ‘base_layout.html‘ as your base template <!DOCTYPE html> <title>Base Layout</title> <div> <h1>Base</h1> …. // write your code here {% block body %}{% endblock %} </div> and then you want to have ‘child_layout.html‘ that extends ‘base_layout. … Read more