python - 属性错误 : module 'jinja2.ext' has no attribute 'autoescape' while trying to use Flask-Babel

标签 python flask python-babel

我是 Flask 和 Babel 的新手,我刚刚开始了一个包含多种语言的项目。生成 babel.cfg 文件后,当我尝试使用命令 pybabel extract -F babel.cfg -o messages.pot . 提取它时,我得到了 AttributeError: module ' jinja2.ext' 没有属性 'autoescape' 错误。

出现此错误的原因是什么,我该如何解决?

谢谢

最佳答案

Jinja2 3.1 中,WithExtensionAutoEscapeExtension 现在是内置的。所以你不再需要这些扩展。 从 babel.cfg 文件中删除这些扩展

[python: **.py]
[jinja2: **/templates/**.html]
;extensions=jinja2.ext.auto escape,jinja2.ext.with_

https://jinja.palletsprojects.com/en/3.1.x/changes/#version-3-0-0

关于python - 属性错误 : module 'jinja2.ext' has no attribute 'autoescape' while trying to use Flask-Babel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72651555/

相关文章:

python - 为 pcolormesh 获取正确的颜色

python - 理解 Python 中的 __init__

python - 在子类中扩展类属性的一种巧妙方法

python - 使用 Flask ping 远程 PC,导致服务器阻塞

python同时获取不同语言的文本

python - mustache 、通天塔和 gettext

python - Flask、Jinja2、 "$"字符上的 Babel 错误

python - Django:使用平面页面时找不到 flatpages/default.html

python - 如何将我的 Flask 应用程序连接到我的 SQLite3 数据库?

python - Flask加载本地json