I am developing a Django 1.3 project that contains multiple apps. The project structure is somewhat like this:
- MyProject
- manage.py
- MyProject
- settings.py
- url.py
- wsgi.py
- core
- models.py
- web
- urls.py
- views.py
- api
- urls.py
- views.py
I would now like to define different handler404 and handler500 for the api app, since it is supposed to return JSON while web returns HTML and can use the default handlers.
Is there a way to override this setting so it is valid for just one app? I really like to avoid running multiple server instances just because of that.
Thanks Simon
Django
httphandler404is global for a site. In your case, you will have to write a wrapper view which depending upon url (or some other attribute inrequest) either returns JSON forapiapp and HTML forwebapp. You can also define separate error handling views inapiandwebcan call them from wrapper view.Reference : Customizing error views