A context decorator for Django views
Project description
django-context-decorator is a Python package for Django removing the need to call super().get_context_data(**kwargs) in nearly every Django view.
Usage
from django_context_decorator import context
from django.utils.functional import cached_property
from django.views.generic import TemplateView
class MyView(TemplateView):
template_name = 'path/to/template.html'
@context
def context_variable(self):
return 'context value'
@context
@property
def context_property(self):
return 'context property'
@context
@cached_property
def expensive_context_property(self):
return 'expensive context property'
Now you’ll have access to {{ context_variable }}, {{ context_property }} and {{ expensive_context_property }} in your template.
Please note: While this package works with the @cached_property decorator, please make sure to add the @context decorator above the @cached_property decorator.
Limitations
Due to the usage of __set_name__, this package is limited to usage with Python 3.6+.
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
Close
Hashes for django_context_decorator-1.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16f637f3d1603653c29b9e5b9a9bf323f771c0a74be24f96f6aa9aba06e3e66e |
|
MD5 | eac6ea8413aeb7018f394ce1080d7192 |
|
BLAKE2b-256 | 0ca91c89f3a00a307649c9c04e01a859abfe8762d8a0ee4987ad9ead6d5a96db |
Close
Hashes for django_context_decorator-1.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d18966ff647708dc522fbc1c319a78f45b55cfbc6c67db36d455d2940a1c759 |
|
MD5 | b6d3f9e08006063d661bbf4c23d8cdfc |
|
BLAKE2b-256 | 0c501f191ae05b092d9a25b900c0e5c3b6587cbfaa6c4001c5f6cb518e487b39 |