semvec/pypi-packages huggingface dataset:
django-json-404-middleware 0.0.1
Django middleware that returns 404s as JSON instead of html
License: MIT

# 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`
drf-ignore-slash-middleware 0.0.1
Django middleware that makes urls ending with and without slashes equivelent
License: MIT

# drf-ignore-slash-middleware
Django middleware that makes urls ending with and without slashes equivalent


When using [DRF](https://www.django-rest-framework.org) routers you have a choice to either have urls end with trailing slash (default) or not. 
i.e `DefaultRouter(trailing_slash=False)`. You can't however have it both ways, as in ignore them.

This package defines a very simple middleware class that removes trailing slashes from urls if they have one.
So in order to ignore trailing slashes and have `/api/some_url` be equivalent to `/api/some_url/` simply install the package and add the middleware class as the first entry in the MIDDLEWARE list. Please note that middleware [changed in django 1.10](https://docs.djangoproject.com/en/1.10/topics/http/middleware/) and this this pacakge requires django version >= 1.10.

```python
MIDDLEWARE = [
	# Should be first entry
	'drf_ignore_slash_middleware.SlashIgnoreMiddleware',
	# Rest of your middleware
]
```