I just wanted to understand something about adding a templates folder in django. This is the code for including my templates folder, that django conveniently made for me:
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? 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.
Here, Django is computing the templates directory by getting the path. Here, windows would have included a \\\\
, hence the .replace
You can read more about it here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.