如何覆盖Django Rest 404处理程序,以便可以拥有动态404页面

时间:2018-11-09 09:05:37

标签: django django-rest-framework custom-exceptions

我尝试了此链接https://stackoverflow.com/a/42036696/6473175,但似乎不起作用,当500加载我的自定义404,html时,当DEBUG=False时,出现了DEBUG=True服务器错误页面。我一直想在下面做类似的事情。

def handler404(request):

    domain = request.META['HTTP_HOST']
    if domain == "mydomain1":
        return render(request, 'index.html', status=404)
    else:
        return render(request, '404.html', status=404)

0 个答案:

没有答案