Django 模板文件扩展名首选项
此Django 票证表示他们不会添加默认的 Django 模板文件扩展名。您使用什么文件扩展名?
This Django ticket says that they will not add a default Django template file extension. What file extension do you use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
老实说,我相信我们需要 django 模板文件的标准扩展名。模板不是有效的 CSS/HTML/XML 或其他任何内容。
尼克·普雷斯塔写道:
第 2 点也可用于支持默认扩展名或混合扩展名(如 .html.djt)。如果没有区分扩展名,您需要打开一个文件才能知道它是 django 模板而不是常规(例如 HTML)文件。
考虑到它们并不总是位于模板目录中,第一点完全是错误的。
I honestly believe we need a standard extension for django template files. A template is NOT valid CSS/HTML/XML or anything else.
Nick Presta wrote:
Point #2 can also be used in favor of a default extension or a mix (like .html.djt). Without a differentiated extension, you need to open a file in order to know it's a django template and not a regular (e.g. HTML) file.
And point #1 is just plain wrong, considering that they are not always in a template directory.
我个人使用 .dj.html
就像我知道里面有什么,我的编辑器知道它包含 django 模板语言。
Personaly I use .dj.html
Like that I know what is inside and my editor knows that it contains django template language.
Ruby on Rails 使用
.html.erb
作为 erb 模板,类似的东西也适用于 Django。Ruby on Rails uses
.html.erb
for erb templates, something similar will work for Django too.对于 HTML 页面:.html
对于 XML 数据(RSS 等):.xml
等等
仅仅因为它们是模板并不意味着它们应该有某种特殊的扩展。
正如票证中提到的:
For HTML pages: .html
For XML data (RSS and such): .xml
Etc
Just because they're templates doesn't mean they should have some sort of special extension.
As mentioned in the ticket:
.djt
它很短,表明该模板是 Django 特定的。
.djt
It's short and shows that the template is Django specific.
如果它不是模板,我将使用与该文件相同的名称。多亏了这一点,我立刻就知道里面会发生什么。对我来说,通过视图提供的每个文件都是一个模板,有时它只是没有填充任何内容,甚至不使用标记语言。
I use the same name I would use for this file, if it wasn't a template. Thanks to this, I instantly know, what to expect inside. And for me every file that is being served is through views is a template, it sometimes just isn't filled with anything or even doesn't use markup language.