Jinja2: "DeprecationWarning: The 'autoescape' extension is deprecated and will be removed in Jinja 3.1."

Viewed 814

With the latest jinja2 bump version to 3.0.0, I started running into this error in my Flask application:

.../anaconda3/envs/env/lib/python3.8/site-packages/jinja2/environment.py:119: DeprecationWarning: The 'autoescape' extension is deprecated and will be removed in Jinja 3.1. This is built in now.
  result[extension.identifier] = extension(environment)
.../anaconda3/envs/env/lib/python3.8/site-packages/jinja2/environment.py:119: DeprecationWarning: The 'with' extension is deprecated and will be removed in Jinja 3.1. This is built in now.
  result[extension.identifier] = extension(environment)

For the record, my current Flask version is 1.1.2.

1 Answers

Simply upgrade your Flask application to the latest version - 2.0.0:

pip install Flask --ignore-installed

That should solve the issue.

However, if upgrading the version is not an option, as an alternative on can just clear the default jinja2 extensions that are initially loaded by Flask by doing:

app = Flask(__name__)
app.jinja_options = {}
...
Related