Skip to main content

Django middleware that returns 404s as JSON instead of html

Project description

# 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`

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-json-404-middleware-0.0.1.tar.gz (2.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_json_404_middleware-0.0.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file django-json-404-middleware-0.0.1.tar.gz.

File metadata

File hashes

Hashes for django-json-404-middleware-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cd38450284e198a05df890296fa87b0fade9ff2dba2380bb4f528b83b750964c
MD5 96b4870d06ba6eff6e36cf95bd8aa76f
BLAKE2b-256 7b26579fc2306bc5899456243e2157f1e593a63300aa0829206a58319d1ee9c9

See more details on using hashes here.

File details

Details for the file django_json_404_middleware-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_json_404_middleware-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e133a7814a70a89188101e21fcd30be79160dcdc8571cdc707729d69c557c72
MD5 acee93783d1a162448db18ccefaba4bf
BLAKE2b-256 e5394a0c23ea89a4ccea614318ac5c16c74e725cb4d8b57970c0df07963d010f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page