繁体   English   中英

在错误的目录中寻找模板

[英]Looking for template in a wrong directory

我已经将Django项目上传到Openshift,并且python代码可以正常工作,但是,我的模板是从错误的文件夹加载的:

/var/lib/openshift/55b9********************/templates

我的settings.py文件包含:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR,  'templates'),
)

正确指向

/var/lib/openshift/55b9********************/app-root/runtime/repo/wsgi/marko/templates

如django的追溯页面所示。 为什么会这样呢? 我可以将模板复制到要查找的文件夹中,但我不想将任何项目文件放在项目文件夹之外。 本地计算机上的runserver在正确的文件夹中查找模板。

您正在运行Django 1.8吗? TEMPLATE_DIRS指令已弃用,并由TEMPLATES代替。

根据文档,您应该像这样更新设置:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            # insert your TEMPLATE_DIRS here
            os.path.join(BASE_DIR, 'templates'),
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
                # list if you haven't customized them:
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

假设BASE_DIR/templates指向正确的目录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM