I understand there's 404 error handling in django. But is it more beneficial to simply put that config in nginx ?
This ST thread has got the solution for putting it. -
Is the fact that how everybody handles it when utilizing nginx ?
I've produced my very own 404.html &lifier 500.html within the sites theme, wish to display them.
You have not pointed out any explanations why you would like to put these pages within the Nginx server. I would suggest keeping it using the relaxation of the site, that's, around the Django server. Moving a part of your website towards the Nginx server may be beneficial to resolve scalability problem, but reduces your deploy. I certainly we do hope you do not see a substantial fraction of the site's traffic visiting your error pages!
I suggest utilizing an in-Django 404/500 handler. You are able to deliver significant alternate nav suggestions inside a page style that's in conjuction with the relaxation of the site.
Make certain you need to do not return a webpage speaking concerning the error but sporting a 200 return status -- human will understand this is an error, but programmatic access won't. I am staying away from saying "search engines like google" here, however that they'll most likely represent 98%+ of the non-human site visitors. See HttpResponse subclasses for particulars.
I did not understand how to configure 404 &lifier 500 errors in django. Because of "namnatulco" who assisted me.
Listed here are the steps:
- Create 2 pages
- Put them inside your modules template folder
Inside your modules
urls.conf, enter both of these lines:
handler404 = "myproject.mymodule.sights.redirect_page_not_found" handler500 = "myproject.mymodule.sights.redirect_500_error"
Inside your view, define the functions
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 drive it by providing some incorrect URL e.g. -
- To check 500 error, within your view, inside your
render_to_response, give an inaccurate URL.
There you have it. You ought to be set.