未找到 Django 模板 [英] Django Template Not Found
问题描述
我有一个 Django 问题,它只是偶尔在查找模板时遇到问题.它将正常运行几个小时,然后突然无法提供某些模板.有时问题会自行纠正,但可以总是通过运行touch
来修复.我目前的解决方案是一个 cronjob,它每分钟执行 touch
,只要 cron 跟上,它就可以工作.但是,我想为我的问题找到合适的解决方案.
I have a Django problem which only occasionally has problems finding Templates. It will be running fine for hours, and then suddenly not be able to serve certain templates. Occasionally the problem will correct itself, but can always be fixed by running touch <template>
. My current solution is a cronjob which executes touch <project root>
every minute, and that works so long as cron keeps up. However, I want to figure out a proper solution to my problem.
相关设置:
PROJECT_ROOT = os.path.dirname(__file__)
APPS_ROOT = os.path.abspath(os.path.join(PROJECT_ROOT, "apps"))
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
TEMPLATE_DIRS = (
(PROJECT_ROOT + '/templates'),
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.request",
"django.core.context_processors.i18n",
"django.contrib.messages.context_processors.messages",
"base_site.context_processors.app_list"
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
推荐答案
所以事实证明我的问题不是与 Django 本身有关,而是与我的环境有关.我正在从 ~/Django-project 运行 Django 服务器,一旦所有会话都被注销,我们的开发服务器就会加密主目录,这意味着服务无法再找到它.将项目移动到/var/并守护 manage.py runserver 命令使项目没有模板不存在错误.
So it turns out my problem was not with Django itself but with my environment. I was running the Django server from ~/Django-project, and our dev server encrypts home directories once all sessions are signed out which means the service could no longer find it. Moving the project to /var/ and daemonizing the manage.py runserver command has kept the project free of Template Does Not Exist errors.
这篇关于未找到 Django 模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!