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`
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-json-404-middleware-0.0.1.tar.gz.
File metadata
- Download URL: django-json-404-middleware-0.0.1.tar.gz
- Upload date:
- Size: 2.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd38450284e198a05df890296fa87b0fade9ff2dba2380bb4f528b83b750964c
|
|
| MD5 |
96b4870d06ba6eff6e36cf95bd8aa76f
|
|
| BLAKE2b-256 |
7b26579fc2306bc5899456243e2157f1e593a63300aa0829206a58319d1ee9c9
|
File details
Details for the file django_json_404_middleware-0.0.1-py3-none-any.whl.
File metadata
- Download URL: django_json_404_middleware-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e133a7814a70a89188101e21fcd30be79160dcdc8571cdc707729d69c557c72
|
|
| MD5 |
acee93783d1a162448db18ccefaba4bf
|
|
| BLAKE2b-256 |
e5394a0c23ea89a4ccea614318ac5c16c74e725cb4d8b57970c0df07963d010f
|