TemplateDoesNotExist atDjango 部署错误

时间:2021-07-14 11:04:57

标签: django templates deployment pythonanywhere

希望你能帮助我。我做了一个 django 项目(只是在研究中)并尝试使用 djangogirls 教程部署它。好的,它有效。但!当我尝试访问我的网站 https://anle93.pythonanywhere.com 时,我有这个:

找不到页面 (404) 请求方式:GET 请求网址:http://anle93.pythonanywhere.com/ 使用在personal_portfolio.urls 中定义的URLconf,Django 按以下顺序尝试了这些URL 模式:

管理员/ 项目/ 空路径与这些都不匹配。

没关系,因为我在所有项目中都没有任何页面。所以。当我去管理员时,它工作(http://anle93.pythonanywhere.com/admin/login/?next=/admin/),我看到用户名和密码字段。当我尝试转到我的“项目”(https://anle93.pythonanywhere.com/projects/) 时,屏幕上出现此错误 first screen。因此,我的项目在屏幕上具有这种结构screen2.2。所以问题是:

我明白,django 找不到 base.html 文件,它扩展了 project_detail.html 和 project_index.html,这是所有项目的 bs4 样式,而不是我制作的这个应用程序,所以,如果我想做任何添加,例如新应用程序中的“project_description.html”,它也会扩展“base.html”。 Ofc,在 localhost 中根据需要工作。我不明白为什么在部署后会发生这种情况。

1 个答案:

答案 0 :(得分:0)

你有什么模板目录配置?

因为你的结构应该是这样的

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