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 throwsTypeErrorif the type is not matched.check_value=HttpResponse: Checks parameters type if set HttpResponse. It throwsHttpResponseif 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-validate-decorators-0.1.0.tar.gz.
File metadata
- Download URL: django-validate-decorators-0.1.0.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8813d5feee702bf605c1bae697569d3d16934abb8f665b0e15cad1ae81756b79
|
|
| MD5 |
3cc5e1ac367b5c50aba87d8e14293552
|
|
| BLAKE2b-256 |
1b1570323711ea1e6a8d7fb177324a39d054f34f24ac6883e8ae20437ebe7334
|
File details
Details for the file django_validate_decorators-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_validate_decorators-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
732e2a6621711e7288f2285e9d6756566bee8ee5295d21c0610da6df81720cef
|
|
| MD5 |
68426d05bf3e5d492d39e98b026a616b
|
|
| BLAKE2b-256 |
6b2a6633468529807f1958043e0e103f37301641b8f8508c4cf073b7713a7fc0
|