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.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13d659ce3ef46d5301bdfc7fcdef1f60b49baedf58c37788304477830f89c4c2 |
|
MD5 | 0162c3ca3681cefb0ae6987bc6f237dd |
|
BLAKE2b-256 | 99512692f8a52a9a7431252696ac1cc133a275993ddd33b550cd207e2f864125 |
Close
Hashes for django_context_decorator-1.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6400d6be661faa4b76541db0d768f3a3ebb2384964f68c54266f7cd5e96820d |
|
MD5 | f8596053ce818e3577684cc3ba0b061d |
|
BLAKE2b-256 | 5fc15dd7f389838ba0a8a461e4916310b0ea246acb117746d4e1d2382d564e79 |