Skip to main content

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' to MIDDLEWARE in your settings
  • optionally, add 'django_early_return' to INSTALLED_APPS, if you want to run our tests when executing python 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

django_early_return-0.0.1.tar.gz (2.1 kB view hashes)

Uploaded Source

Built Distribution

django_early_return-0.0.1-py3-none-any.whl (4.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page