django tutorial: custom 404 and 500 views

自作多情 提交于 2019-12-01 17:33:10
Shopper

As I can see you have a little mistake, but dont worry.

Look, try this:

handler404 = 'mysite.views.error404'

Then in mysite (the second mysite) creates a views.py if you dont have. In that views.py put:

from django.shortcuts import render

def error404(request):
    return render(request,'404.html')

and thats all! In templates, create that file and do something nice!

Remember that only works in production (DEBUG=False) otherwise django use the traceback. Is the same for 505, and you maybe can try handler404 = 'polls.views.see404' and put in the views.py then but you know, tastes are different hehehe.

Now, try something else, for example: comment in the urls.py

#handler404 = 'mysite.views.error404'

and remove too in the views.py the def.

In the index of your templates file creates a simple 404.html. Run the server in production and produce that 404 error, what happened?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!