简体   繁体   English

在django中添加模板目录

[英]Adding template directory in django

I just wanted to understand something about adding a templates folder in django. 我只想了解一些关于在django中添加模板文件夹的内容。 This is the code for including my templates folder, that django conveniently made for me: 这是包含我的模板文件夹的代码,django方便我为我做的:

TEMPLATE_DIRS = (
    # This includes the templates folder
    os.path.join(os.path.dirname(__file__), '..', 'templates').replace('\\','/'),
)

What I do not understand is the part with 'templates' , why is it not '/templates' , or even \\\\templates in the case of something Unix based? 我不明白的是带有'templates'的部分,为什么它不是'/templates' ,甚至是基于Unix的情况下的\\\\templates I come here after reading this article , in particular the part about Template Loading . 我在阅读本文后来到这里,特别是有关模板加载的部分。

os.path.join is building the absolute path based on the operating system being used. os.path.join正在根据正在使用的操作系统构建绝对路径。

Here, Django is computing the templates directory by getting the path. 在这里,Django通过获取路径来计算模板目录。 Here, windows would have included a \\\\ , hence the .replace 这里,windows会包含一个\\\\ ,因此包含.replace

You can read more about it here 你可以在这里阅读更多相关信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM