Skip to content

DJango middleware that returns 404s as JSON instead of default html response

License

Notifications You must be signed in to change notification settings

ah450/django-json-404-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 and thus this pacakge requires django version >= 1.10.

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

Installation

pip install django-json-404-middleware

About

DJango middleware that returns 404s as JSON instead of default html response

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages