没有找到Django模板 [英] Django Template Not Found

查看:160
本文介绍了没有找到Django模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个django问题,只是偶尔有问题找到模板。它会运行好几个小时,然后突然无法提供某些模板。偶尔问题会自动纠正,但是可以通过运行 touch< template> 来修复 。我目前的解决方案是每分钟执行 touch< project root> 的cronjob,只要cron保持起来,它就可以工作。但是,我想找出一个适合我的问题的解决方案。



相关设置:

  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服务器,所有会话都注销后,我们的dev服务器会加密主目录,这意味着服务无法再找到它。将项目移动到/ var /并守护manage.py runserver命令,使项目不受模板不存在错误。


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.

Relevant Settings:

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',
)

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆