【发布时间】:2012-06-28 18:15:53
【问题描述】:
我正在 heroku 上构建一个 django 应用程序,但在使用 os.path 模块时遇到了很多麻烦。我的项目无法在 heroku 上找到 templates,而它在 localhost 上运行良好。
这是我的项目层次结构(简而言之):
project/
project/
settings.py
urls.py
views.py
..
manage.py
templates/
css/
media/
Templates/
home.html
所以,我使用os.path 在settings.py 中添加模板目录。
currDir = os.path.dirname(__file__)
templateDir = os.path.join(os.path.join(os.path.split(currDir)[0], "templates"), "templates")
TEMPLATE_DIRS = (
templateDir,
)
这在我的本地主机上运行良好,但在 Heroku 上运行不正常。
以下是在heroku上提到的(在heroku上运行)
Django 尝试按以下顺序加载这些模板:
使用加载器 django.template.loaders.filesystem.Loader:
/app/templates/templates/home.html (File does not exist)*使用加载器 django.template.loaders.app_directories.Loader:*
/app/.heroku/venv/lib/python2.7/site-packages/django/contrib/auth/templates/home.html(File does not exist)
【问题讨论】:
-
为什么你的模板文件夹中有css和media?
-
@ArgsKwargs 它不在包含模板的文件夹中。它就在名为“模板”的文件夹中。我知道它有点混乱。
-
@ArgsKwargs 我认为这个问题不应该打扰
标签: python django heroku django-templates