Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Heroku Django,templatedoesnotexist错误_Django_Templates_Heroku - Fatal编程技术网

Heroku Django,templatedoesnotexist错误

Heroku Django,templatedoesnotexist错误,django,templates,heroku,Django,Templates,Heroku,所以经过几次深夜工作后,我终于将我的应用程序部署到了Heroku上,但现在又出现了另一个问题,《不眠之夜》,该模板不存在 错误, 我使用的是Django.1.11,所以我的设置如下 INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib

所以经过几次深夜工作后,我终于将我的应用程序部署到了Heroku上,但现在又出现了另一个问题,《不眠之夜》,该模板不存在

错误, 我使用的是Django.1.11,所以我的设置如下

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'storages',
    'photos',
]
我的模板如下所示,从文档中,安装的应用程序(app_DIR设置为true)将在应用程序中查找TEMPLATES文件夹

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]
最后是我的应用程序结构

|mysite
|照片
----|模板
--------|照片
------------|index.html

当我加载页面时,我可以从日志中看到

Using engine django:
django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python2.7/site-packages/django/contrib/admin/templates/photos/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python2.7/site-packages/django/contrib/auth/templates/photos/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/photos/templates/photos/index.html (Source does not exist)
最后一行,显示了正确的路径,但不知怎么的,它找不到,我真的不知道为什么,有人可以发光

谢谢
Jimmy

如果要显式添加模板文件夹的路径,可以如下设置:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR,'photos/templates/photos/templates'),
        ],
        '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',
            ],
        },
    },
]

最后一个没有显示正确的路径,它显示了
/app/photos/templates/photos/index.html
,但该模板的路径是:
/app/photos/templates/photos/templates/index.html
@Nazkter/app应该指向照片吗?我的结构中有一个输入错误,最后一个templates文件夹不应该在那里,所以路径应该是正确的,出乎意料的是,我可以在同一个文件夹下打开登录和注册html,但不能打开index.html。我想我自己找到了答案,不知怎的,index.html被保留了?在我将页面更改为main.html之后,一切似乎都正常工作。很奇怪。