2013-03-15 97 views

回答

1
import os 
import sys 

PORJECT_ROOT = os.path.join(os.path.dirname(__file__),'..') 
sys.path.insert(0, os.path.join(PROJECT_ROOT,'static')) 
0

确保文件夹包含在TEMPLATE_DIRS设置中(位于settings.py中)。

+0

我该如何硬编码那里的路径。像'myproject.static'或其他东西 – user1865341 2013-03-15 03:06:02

+0

硬代码?对不起,我不明白你想做什么。首先,'template_name'出现错误。它应该是“static/site/app/index.html”,而不是“/static/site/app/index.html”,因为它被解释为来自'TEMPLATE_DIRS'中的其他路径的relativa路径。因此,添加保存文件夹static(e:“C:/ myprject/myapp /”或“/ home/django/myproject/myapp /”)的绝对路径。 – sanfilippopablo 2013-03-15 03:17:25

0

一般(按照约定)模板文件夹是project_root_folder \ Templates文件夹,更新TEMPLATE_DIRS在settings.py:

import os 
PORJECT_ROOT = os.path.dirname(os.path.dirname(__file__)) 
TEMPLATE_DIRS = (
    os.path.join(PORJECT_ROOT, 'templates'), 
) 

虽然静态商店只有JavaScript/CSS /图像fiels。

这将使未来的开发和部署更容易。

0

默认情况下,django会在app/templates目录中检查模板匹配,或者在project_root/templates /中检查。您应该像其他人所说的那样,在TEMPLATE_DIRS设置中列出目录。

相关问题