Metadata-Version: 2.0
Name: django-json-404-middleware
Version: 0.0.1
Summary: Django middleware that returns 404s as JSON instead of html
Home-page: https://github.com/ah450/django-json-404-middleware
Author: Ahmed Hisham Ismail
Author-email: ahm3d.hisham@gmail.com
License: MIT
Platform: UNKNOWN
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 1.10
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: License :: OSI Approved :: MIT License

# django-json-404-middleware
DJango middleware that returns 404s as JSON instead of default html response


When using Django for a restuful API, for example with DRF, it makes sense to return errors as JSON, which is what happens with 400s, 403s, etc. since they are generated by DRF themselves i.e `serializer.is_valid(raise_exception=True)` This however is not the case with 404s.
This middleware remedies this problem by intercepting 404 responses and turning them into JSON responses.

Please note that middleware [changed in django 1.10](https://docs.djangoproject.com/en/1.10/topics/http/middleware/) and thus this pacakge requires django version >= 1.10.


```python
MIDDLEWARE = [
	# Should come after any django middleware such as CommonMiddleware
	'django_json_404_middleware.JSON404Middleware',
]
```

# Installation
`pip install django-json-404-middleware`

