Django/Heroku - 自定义 500 模板

问题描述 投票:0回答:1

我在 S3 上定义并加载了一个模板。该模板已被授予公共访问权限。

该模板在 Heroku 中被称为变量

ERROR_PAGE_URL
,并且 S3 链接附加到该变量。

不知何故,模板没有显示,但我仍然收到生成的基本 500 错误:

500 Internal Server Error
Exception inside application.

Daphne

我(我认为)应用了与自定义维护模板相同的方法,它呈现得非常好。

我阅读的文档错误吗? (https://devcenter.heroku.com/articles/error-pages)

我使用的变量正确吗?或者它实际上不是 Heroku 生成的东西,我应该在 django 中编码?

django heroku
1个回答
0
投票

事实证明我错了。

考虑删除该帖子,但后来我想,这可能对某人有用。

我遵循了本教程:https://www.youtube.com/watch?v=-5wFWpKQazA

为了简单起见,添加以下代码:

views.py

#Error Handling Templates
def custom_500(request):
    return render(request,'AppName/500.html', status=500) #AppName/ does not have to be there, this was for me.

urls.py:(在您的项目文件夹中,而不是应用程序)

#error handling
from django.conf.urls import handler500
handler500 = 'main.views.custom_500'

在模板文件夹中创建一个名为“500.html”的模板

这对我有用。

(显然在你的设置中将 debug 切换为 False)

© www.soinside.com 2019 - 2024. All rights reserved.