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.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b058f9bcc041cdf2053ed94d3653afe5179b22abaec94f14d75ad2cb1fd6eb38 |
|
MD5 | 4981b9051c0ed4cc7a8cab119eb9e044 |
|
BLAKE2b-256 | 2ca633032c23ae16b452ca6a551c08b2281aac54cca7752d5827968daf000804 |
Close
Hashes for django_context_decorator-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09671e4b96e816382e5c009c428970fb762a82e1fbc9c01fd9062d8316350f64 |
|
MD5 | 1c40c85e57b8fec6f5608ba1311da711 |
|
BLAKE2b-256 | 855af921947e20c912d5949be569693cdf2aa412140a1c66725ab6961cca3b4e |