为我的django项目中的每个应用创建自定义404错误?

时间:2016-01-31 01:57:52

标签: python django custom-error-pages

有没有办法为我的Django项目中的每个应用程序创建多个自定义错误模板,我的意思是,在我的项目中我有3个应用程序,我将为每个应用程序显示3个不同的海关404错误。

现在我正在为我的后台应用程序和前台显示相同的404错误页面。

1 个答案:

答案 0 :(得分:4)

创建自定义error view并将其分配到根Scanner stdin = new Scanner(System.in); char exit = 'n'; while( exit != 'n' ) { // your old code here System.out.println("Play again ? (y/n):") exit = stdin.next().charAt(0); } 中的handler404变量:

urls.py

此代码适用于django 1.9。如果您使用django< = 1.9,则从视图中删除from django.views.defaults import page_not_found def my_error_404(request, exception): template_name = '404.html' if request.path.startswith('/backoffice/'): template_name='backoffice/404.html' elif request.path.startswith('/frontoffice/'): template_name='frontoffice/404.html' return page_not_found(request, exception, template_name=template_name) 参数。