TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['/path/to/your/templates/'],
'APP_DIRS': True,
...
},
]
$ ls -l /path/to/your/templates/
-rw-r--r-- 1 user group 2383 Mar 5 14:39 my_template.html
$ chmod 644 /path/to/your/templates/my_template.html
如果您使用的是 Django 1.8 或更早版本,请确保您的模板目录包含一个名为 init.py 的文件。这是因为 Django 1.8 在加载模板时使用了 Python 包的机制。
如果您使用的是 Apache 服务器,检查 Apache 用户(通常是 www-data)是否具有访问您的模板目录的权限。可以将 www-data 用户添加到您的模板目录所在的组中,并赋予组成员访问权限。例如:
$ sudo adduser www-data your_group
$ sudo chgrp -R your_group /path/to/your/templates/
$ sudo chmod -R g+r /path/to/your/templates/