Conference organisation: CfPs, scheduling, much more
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.0.0.post1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd8ce0c5905be7f8cb2028620957e1225126099fe65e9999ed55c53448768b39 |
|
MD5 | 72294f6426c6d26d54772b5a78a188e0 |
|
BLAKE2b-256 | cab2c83c2b59dc0735596be25a0f2d3f1c3886b1013719be23c001945523c30e |
Close
Hashes for django_context_decorator-1.0.0.post1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0af53ad13a287b058ef7ec28944cbbb461007c92ea87f91d0d846519b21c2874 |
|
MD5 | cacd12b23617d6725186645775aebb54 |
|
BLAKE2b-256 | 96f14b668319ed5f8c3e73c0ebfa0da57316d49269ebdd3f539c4b4163920d0d |