mirror of
https://github.com/django-components/django-components.git
synced 2025-08-03 13:58:16 +00:00
refactor: Fix template caching, expose cached_template
, Component.template API changes (#647)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
589e802625
commit
841dd77e91
14 changed files with 347 additions and 56 deletions
|
@ -3,10 +3,14 @@ from django_components import Component, register
|
|||
|
||||
@register("calendar")
|
||||
class Calendar(Component):
|
||||
# Note that Django will look for templates inside `[your apps]/components` dir and
|
||||
# `[project root]/components` dir. To customize which template to use based on context
|
||||
# you can override def get_template_name() instead of specifying the below variable.
|
||||
# Templates inside `[your apps]/components` dir and `[project root]/components` dir
|
||||
# will be automatically found.
|
||||
#
|
||||
# `template_name` can be relative to dir where `calendar.py` is, or relative to STATICFILES_DIRS
|
||||
template_name = "calendar/calendar.html"
|
||||
# Or
|
||||
# def get_template_name(context):
|
||||
# return f"template-{context['name']}.html"
|
||||
|
||||
# This component takes one parameter, a date string to show in the template
|
||||
def get_context_data(self, date):
|
||||
|
@ -27,10 +31,14 @@ class Calendar(Component):
|
|||
|
||||
@register("calendar_relative")
|
||||
class CalendarRelative(Component):
|
||||
# Note that Django will look for templates inside `[your apps]/components` dir and
|
||||
# `[project root]/components` dir. To customize which template to use based on context
|
||||
# you can override def get_template_name() instead of specifying the below variable.
|
||||
# Templates inside `[your apps]/components` dir and `[project root]/components` dir
|
||||
# will be automatically found.
|
||||
#
|
||||
# `template_name` can be relative to dir where `calendar.py` is, or relative to STATICFILES_DIRS
|
||||
template_name = "calendar.html"
|
||||
# Or
|
||||
# def get_template_name(context):
|
||||
# return f"template-{context['name']}.html"
|
||||
|
||||
# This component takes one parameter, a date string to show in the template
|
||||
def get_context_data(self, date):
|
||||
|
|
|
@ -3,10 +3,14 @@ from django_components import Component, register
|
|||
|
||||
@register("calendar_nested")
|
||||
class CalendarNested(Component):
|
||||
# Note that Django will look for templates inside `[your apps]/components` dir and
|
||||
# `[project root]/components` dir. To customize which template to use based on context
|
||||
# you can override def get_template_name() instead of specifying the below variable.
|
||||
# Templates inside `[your apps]/components` dir and `[project root]/components` dir
|
||||
# will be automatically found.
|
||||
#
|
||||
# `template_name` can be relative to dir where `calendar.py` is, or relative to STATICFILES_DIRS
|
||||
template_name = "calendar.html"
|
||||
# Or
|
||||
# def get_template_name(context):
|
||||
# return f"template-{context['name']}.html"
|
||||
|
||||
# This component takes one parameter, a date string to show in the template
|
||||
def get_context_data(self, date):
|
||||
|
|
|
@ -2,8 +2,7 @@ from django_components import Component, register
|
|||
|
||||
|
||||
@register("todo")
|
||||
class Calendar(Component):
|
||||
# Note that Django will look for templates inside `[your apps]/components` dir and
|
||||
# `[project root]/components` dir. To customize which template to use based on context
|
||||
# you can override def get_template_name() instead of specifying the below variable.
|
||||
class Todo(Component):
|
||||
# Templates inside `[your apps]/components` dir and `[project root]/components` dir
|
||||
# will be automatically found.
|
||||
template_name = "todo/todo.html"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue