Skip to main content

Throwing web exceptions like in AioHTTP

Project description

https://badge.fury.io/py/django-web-exceptions.svg https://travis-ci.org/samael500/web-exceptions.svg?branch=master https://codecov.io/gh/samael500/web-exceptions/branch/master/graph/badge.svg

Throwing web exceptions like in AioHTTP

What and why?

In AioHTTP you cat raise any response as exception (this is very cool). But Django can raise only 3+1 web exceptions.

This package allow you to raise as exception any on HTTP response.

Quickstart

Install Django Web Exceptions:

pip install django-web-exceptions

Add it to your MIDDLEWARE:

MIDDLEWARE = (
    # ...
    'web_exceptions.middleware.WebExceptionsMiddleware',
    # ...
)

Features

Import exceptions and raise anywhere

from web_exceptions import exceptions

# ...

def index(request):
    """ Simple view raise redirectexception """
    raise exceptions.HTTPMovedPermanently('/foo')

Also you cat 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>

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package:

History

0.1.0 (2017-05-13)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-web-exceptions, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size django_web_exceptions-0.1.0-py2.py3-none-any.whl (7.0 kB) File type Wheel Python version 3.6 Upload date Hashes View
Filename, size django-web-exceptions-0.1.0.tar.gz (7.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page