【发布时间】:2023-03-03 19:43:01
【问题描述】:
我是 Python/Django 的新手,但我正在尝试在 AWS Elastic Beanstalk 中发布一个应用程序,但它没有找到 一些 模板。
当我请求http://www.example.com/path 时,它会抛出一个错误:TemplateDoesNotExist at /path
它说:
Error during template rendering
In template /opt/python/bundle/5/app/src/app_name/templates/app_name/tmpl.djhtml, error at line 1
1 {% extends 'app_name/base.djhtml ' %}
2 ...
因此,它会加载主模板,但不会加载使用extends 指定的模板。更糟糕的是,它说:
Django tried loading these templates, in this order:
Using engine django:
...
django.template.loaders.app_directories.Loader:
/opt/python/bundle/5/app/src/app_name/templates/app_name/base.djhtml (Source does not exist)
如果我通过 SSH 连接到服务器,该文件确实存在!它也适用于我的 Windows 机器。
如果我在该目录中执行ls -hal,则两个文件的权限相同:
-rw-r--r-- 1 wsgi root 512 Oct 21 17:18 tmpl.djhtml
-rw-r--r-- 1 wsgi root 3.0K Oct 21 17:18 base.djhtml
模板设置如下:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates').replace('\\','/'),],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
有什么想法吗?谢谢。
【问题讨论】:
标签: python django amazon-web-services django-templates amazon-elastic-beanstalk