Python PyCharm 是否支持 Jinja2?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15750551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 20:53:12  来源:igfitidea点击:

Does PyCharm support Jinja2?

pythonjinja2pycharm

提问by k0pernikus

A bottle project of mine uses Jinja2. PyCharm does not automatically recognize it and shows such lines as errors. Is there a way to make Jinja2 work?

我的一个瓶子项目使用 Jinja2。PyCharm 不会自动识别它,并将此类行显示为错误。有没有办法让 Jinja2 工作?

采纳答案by k0pernikus

In the pro edition, these template languages:

在专业版中,这些模板语言:

  • Jinja2
  • Django
  • Mako
  • Jinja2
  • 姜戈
  • 真子

are supported. You can configure the template language in the project's settings:

支持。您可以在项目的设置中配置模板语言:

In Python Template Settings the template langauge is set to Jinja2

在 Python 模板设置中,模板语言设置为 Jinja2

The community edition may lack certain template languages.

社区版可能缺少某些模板语言。

回答by Stan Prokop

I think it's worth to mention that PyCharm Community edition does not support Jinja2, Mako and Django. It's available only in PyCharm Professional.

我觉得值得一提的是,PyCharm 社区版不支持 Jinja2、Mako 和 Django。它仅在 PyCharm Professional 中可用。

See comparisonof the two.

参见两者的比较

回答by Ayoub

enter image description hereYes pro edition from pycharm does support Jinja2to enable it go here

在此处输入图片说明是的,pycharm 的专业版确实支持 Jinja2以启用它

From Fileopen Settingsand searchfor python templateunder Languages & Frameworks SelectPython Template Languages from there Click HTML And Select Jinja2 as Template Language.

文件打开设置搜索蟒蛇模板下的语言与框架选择从那里的Python语言模板HTML点击并选择使用Jinja2作为模板语言。

please see the image for better understanding.

请查看图片以便更好地理解。

回答by Hyman Black

If yoy are using .jinjaextension instead of .jinja2, it won't work, templates are not highlighted.

如果 yoy 使用.jinja扩展名而不是.jinja2,它将不起作用,模板不会突出显示。

You have to add the file extension to the filetypes section.

您必须将文件扩展名添加到文件类型部分。

  • Preferences > General > Filetypes
  • Scroll to Jinja 2 Template
  • Register new pattern by clicking +, add *.jinja
  • 首选项 > 常规 > 文件类型
  • 滚动到 Jinja 2 模板
  • 单击 + 注册新模式,添加 *.jinja

enter image description here

在此处输入图片说明