Allows view code to exit early and return a given HttpResponse by raising an exception
Project description
django_early_return
Installation
pip install django_early_return
- add
'django_early_return.EarlyReturnMiddleware'
toMIDDLEWARE
in your settings - optionally, add
'django_early_return'
toINSTALLED_APPS
, if you want to run our tests when executingpython manage.py test
Usage
Any view code (or middleware code, if that middleware is installed after EarlyReturnMiddleware) can now instantiate EarlyReturn with any HttpResponse, and that response will be returned to the user:
if not request.user.has_perm('my_app.some_permission'):
raise django_early_return.EarlyReturn(http.HttpResponseForbidden())
For code in helper functions/middleware/etc., this is often more convenient than passing a response back to the actual view code.
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
Built Distribution
File details
Details for the file django_early_return-0.3.0.tar.gz
.
File metadata
- Download URL: django_early_return-0.3.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c8ae7d10d68c84c78624fe70f438a79e7e3702890d6213b96d656875993044c |
|
MD5 | fe20f82b4656c96dd4fba5b36a7448a4 |
|
BLAKE2b-256 | a698d0c6965cf7b0e9826e63c8552fba84b694315a6a75e744c215fce3ff2528 |
File details
Details for the file django_early_return-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: django_early_return-0.3.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08fc717e574d907bfe425243da22bebcaeff12fd70319b15b1b4e1cf714ac027 |
|
MD5 | 2e693db2e7ac7131460dd2b1bfe5f693 |
|
BLAKE2b-256 | 2b13144a94bf421c94e59cc6c3a8a0456654cb11d597855825e313b651eddf1c |