Skip to main content

Useful decorators for Django views

Project description

Django Decorators

This Python package provides a collection of decorators for Django views to streamline handling of request types and parameters.

Installation

You can install the package using pip:

pip install django-validate-decorators

Usage

Import the desired decorators from the package and apply them to your view functions:

from django.http import HttpResponse
from decorators import pass_only_get, pass_json_body

@pass_only_get
def my_view(request, name: str, age: int):
    # Your view logic
    # Use name and age here
    return HttpResponse('Hello World.')

Features

  • pass_only_get: Ensures that the view only processes GET requests.
  • pass_only_post: Ensures that the view only processes POST requests.
  • pass_only_post_and_get: Ensures that the view only processes POST and GET requests.
  • pass_json_body: Parses and validates JSON request bodies.

Config

You can pass parameters to check types and values of request parameters. The following parameters are available:

  • check_type=False: Checks parameters type, if set True. (Default: False), it throws TypeError if the type is not matched.
  • check_value=HttpResponse: Checks parameters type if set HttpResponse. It throws HttpResponse if the value is not matched.
  • check_value=Exception: You can customize your own exception class. It throws your exception if the value is not matched.

Contributing

Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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-validate-decorators-0.1.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

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

django_validate_decorators-0.1.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file django-validate-decorators-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django-validate-decorators-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8813d5feee702bf605c1bae697569d3d16934abb8f665b0e15cad1ae81756b79
MD5 3cc5e1ac367b5c50aba87d8e14293552
BLAKE2b-256 1b1570323711ea1e6a8d7fb177324a39d054f34f24ac6883e8ae20437ebe7334

See more details on using hashes here.

File details

Details for the file django_validate_decorators-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_validate_decorators-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 732e2a6621711e7288f2285e9d6756566bee8ee5295d21c0610da6df81720cef
MD5 68426d05bf3e5d492d39e98b026a616b
BLAKE2b-256 6b2a6633468529807f1958043e0e103f37301641b8f8508c4cf073b7713a7fc0

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