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.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 662105fec57253b9cfe0b01e05e81f3b4d80ed7354bc8524de195715062ab081 |
|
MD5 | 3d6c5945f75f7f515984aac6ad3fc765 |
|
BLAKE2b-256 | a5bb1f1773b53321dd31f313d66f178fa5a3a7102ba978549483272c6c1c01a4 |
Close
Hashes for django_context_decorator-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a158dbebc428a84819e961369f273a1b9e8e295b4d80d4387aa035280fb40a6b |
|
MD5 | d4a1d342549b24f85a6aa1b200d57cc7 |
|
BLAKE2b-256 | 674e18957dce5a8764982cd9dc726dd7561db9a409ded6aa446280874b2f9750 |