Django on nginx & apache: where to handle error 404 and 500?

I know that error handling in django is done 404. But is it better to just install this config in nginx?

This ST stream has a solution for hosting it. - http://stackoverflow.com/questions/1024199/nginx-customizing-404-page

Is this how everyone processes it when using nginx?
I created my own 404.html and 500.html in the sites topic, I want to display them.

+4
source share
3 answers

You did not specify any reasons why you would like to host these pages on the Nginx server. I would recommend storing it with the rest of your site, i.e. on a Django server. Moving part of your site to the Nginx server is a good idea to solve the scalability problem, but complicates the deployment. Of course, I hope that you will not see a significant part of the traffic of your site on the error pages!

+3
source

I did not know how to configure 404 and 500 errors in django. Thanks to namnatulco for helping me.

Here are the steps:

  • Create 2 pages 404.html and 500.html
  • Put them in the module templates folder
  • In your urls.conf modules urls.conf enter the following two lines:

      handler404 = "myproject.mymodule.views.redirect_page_not_found"   
     handler500 = "myproject.mymodule.views.redirect_500_error"
    
  • Define functions in your view

      def redirect_page_not_found (request):
       return render_to_response ('logreg / 404.html', {}, context_instance = RequestContext (request));     
     def redirect_500_error (request):
       return render_to_response ('logreg / 500.html', {}, context_instance = RequestContext (request));     
    
  • Test it with an invalid url, for example. - www.mydomain.com/aaaaaaaaaaaaaaaa

  • To check for a 500 error inside your view in render_to_response , enter the wrong url.

What is it. You must be installed.

+3
source

I recommend using the in-Django 404/500 handler. You can provide meaningful alternative navigation options in a page style that is consistent with the rest of your site.

Make sure that you do not return a page saying an error, but having a return status of 200, a person will understand this error, but there will be no programmatic access. I avoid saying “search engines” here, but the truth is that they are likely to represent 98% + of your inhuman visitors. See subclasses of HttpResponse for more details.

+1
source

All Articles