Metadata-Version: 2.0
Name: django-web-exceptions
Version: 0.1.4
Summary: Throwing web exceptions like in AioHTTP
Home-page: https://github.com/samael500/web-exceptions
Author: Maks Skorokhod
Author-email: samael500@gmail.com
License: MIT
Keywords: web-exceptions,django,web,exceptions,http,response
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Django
Classifier: Framework :: Django :: 1.10
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Requires-Dist: Django (>=1.10)

=============================
Django Web Exceptions
=============================

.. image:: https://badge.fury.io/py/django-web-exceptions.svg
    :target: https://badge.fury.io/py/django-web-exceptions

.. image:: https://travis-ci.org/samael500/web-exceptions.svg?branch=master
    :target: https://travis-ci.org/samael500/web-exceptions

.. image:: https://codecov.io/gh/samael500/web-exceptions/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/samael500/web-exceptions

.. image:: https://readthedocs.org/projects/web-exceptions/badge/?version=latest
    :target: http://web-exceptions.readthedocs.io/en/latest/
    :alt: Documentation Status

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.

- `400` `SuspiciousOperation <https://docs.djangoproject.com/en/1.11/ref/exceptions/#suspiciousoperation>`_
- `403` `PermissionDenied <https://docs.djangoproject.com/en/1.11/ref/exceptions/#permissiondenied>`_
- `404` `Http404 <https://docs.djangoproject.com/en/1.11/topics/http/views/#the-http404-exception>`_
- `500` Any other non catched exception

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

.. And configure any custome `handlerXXX` for that.

Documentation
-------------

The full documentation is at https://web-exceptions.readthedocs.io.

Quickstart
----------

Install Django Web Exceptions::

    pip install django-web-exceptions

Add it to your `MIDDLEWARE`:

.. code-block:: python
    :caption: settings.py

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

Features
--------

Import exceptions and raise anywhere

.. code-block:: python
    :caption: views.py

    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 <https://docs.djangoproject.com/en/1.11/topics/http/views/#customizing-error-views>`_ .

.. code-block:: python
    :caption: urls.py

    from myapp import views

    handler300 = <callable view>
    handler400 = <callable view>
    handler<status_code> = <callable view>

For more example see `example proj <https://github.com/samael500/web-exceptions/tree/master/example>`_


Running Tests
-------------

Does the code actually work?

::

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

Credits
-------

Tools used in rendering this package:

*  Cookiecutter_
*  `cookiecutter-djangopackage`_

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage
.. _AioHTTP: https://github.com/aio-libs/aiohttp




History
-------

0.1.4 (2017-05-28)
++++++++++++++++++

* Set custom reason phrase for exception response.
* Add docs.

0.1.3 (2017-05-15)
++++++++++++++++++

* Fix pypi wrong upload issue.

0.1.2 (2017-05-15)
++++++++++++++++++

* Clean source code from unused rows.

0.1.1 (2017-05-13)
++++++++++++++++++

* Small fixes in source code and readme.

0.1.0 (2017-05-13)
++++++++++++++++++

* First release on PyPI.


