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
Close
Hashes for django_early_return-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91144d29d0fa8aad78aae2b6ad5066759e3cf99b168834b6114423650eee0657 |
|
MD5 | 44784dd00935b9ccbc5be22d352fffcd |
|
BLAKE2b-256 | 9dad14dba4e6d0c2dbc0ad7199aa27ad7ce04e1cb95d4a2a5f479936e1d447ef |
Close
Hashes for django_early_return-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a5726670aa0f6f4ca2c0664aabe6022f0c11602f92912d0c7ebee95cefe1339 |
|
MD5 | df4a55f88a8a44d8e33a7c997ebd2ea8 |
|
BLAKE2b-256 | 732b0dcbf3ffa98ffa25ea7e597b0328a98783f49e38b84ded8eccafa4357b99 |