Throwing web exceptions like in AioHTTP
Project description
Throwing web exceptions like in AioHTTP
What and why?
In AioHTTP you can raise any response as exception (this is very cool). But Django can raise only 3+1 web exceptions.
- 400 SuspiciousOperation
- 403 PermissionDenied
- 404 Http404
- 500 Any other non catched exception
This package allow you to raise as exception any of HTTP response.
Documentation
The full documentation is at https://web-exceptions.readthedocs.io.
Quickstart
Install Django Web Exceptions:
pip install django-web-exceptions
Add it to your MIDDLEWARE:
# settings.py MIDDLEWARE = ( # ... 'web_exceptions.middleware.WebExceptionsMiddleware', # ... )
Features
Import exceptions and raise anywhere
# views.py from web_exceptions import exceptions # ... def index(request): """ Simple view raise redirectexception """ raise exceptions.HTTPMovedPermanently('/foo')
Also you can customize any kind of exception status code as custom handler, defined in urls.py like django error handlers .
# urls.py from myapp import views handler300 = <callable view> handler400 = <callable view> handler<status_code> = <callable view>
For more example see example proj
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size django_web_exceptions-0.1.4-py2.py3-none-any.whl (7.3 kB) | File type Wheel | Python version 3.6 | Upload date | Hashes View |
Filename, size django-web-exceptions-0.1.4.tar.gz (7.7 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for django_web_exceptions-0.1.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5370c7bb18cfaa337e1c030630236df3f0a23c343c46495fcf31dd4f07e473dc |
|
MD5 | 19f4812bc964efa63e5e4bc8a917993a |
|
BLAKE2-256 | 16e081706143b600b5bcbe4bc591dbc9bded0eecc636b33be267ba73a36d6eed |
Close
Hashes for django-web-exceptions-0.1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee0b547090c0b5998cbe5f1d722ce86045c20340a445723bc761d38647053c3e |
|
MD5 | 7a9837218bbde24ca33e2f394c9205ff |
|
BLAKE2-256 | 4e830b5ae39f88581f82d912dd22a590730ebe459d5c05992e6a3ee46bcbc6f7 |