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 can 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 of 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 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

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.

Source Distribution

django-web-exceptions-0.1.1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_web_exceptions-0.1.1-py2.py3-none-any.whl (7.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-web-exceptions-0.1.1.tar.gz.

File metadata

File hashes

Hashes for django-web-exceptions-0.1.1.tar.gz
Algorithm Hash digest
SHA256 70f37ffb96955411ab13e71dc5262f20984592d34b17908cfe81cd0077973cec
MD5 8c80a426f871bf90429389cdfa21f534
BLAKE2b-256 a9896680bfcfaead86330f0ac2d7590a04ac9b1b505cf83687ac87e22b820970

See more details on using hashes here.

File details

Details for the file django_web_exceptions-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_web_exceptions-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6f66b639f782c223df09e35b16a3681518425fe8d368570e972b6cc42b052453
MD5 fea4a8713d2f12780782bb61168f40d0
BLAKE2b-256 05c92a803fde41aec7a8591b5a9627717820393981f7ba1a468b7cf85d761168

See more details on using hashes here.

Supported by

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