Require get_context_data set to accept parameters.

This commit is contained in:
Emil Stenström 2021-09-10 12:25:35 +02:00
parent fa3731422f
commit a2f0e2246b
3 changed files with 12 additions and 2 deletions

View file

@ -190,8 +190,15 @@ from django_components import component
@component.register("calendar")
class Calendar(component.Component):
# Note that Django will look for templates inside `[your app]/components` dir
# To customize which template to use based on context override get_template_name instead
template_name = "calendar/calendar.html"
# This component takes one parameter, a date string to show in the template
def get_context_data(self, date):
return {
"date": date,
}
class Media:
css = '[your app]/components/calendar/calendar.css'
js = '[your app]/components/calendar/calendar.js'

View file

@ -49,8 +49,8 @@ class Component(metaclass=SimplifiedInterfaceMediaDefiningClass):
self.instance_template = None
self.slots = {}
def get_context_data(self, *args, **kwargs):
return kwargs
def get_context_data(self):
return {}
def get_template_name(self, context=None):
if not self.template_name:

View file

@ -11,6 +11,9 @@ from .testutils import create_and_process_template_response, Django30CompatibleS
class SimpleComponentAlternate(component.Component):
template_name = "simple_template.html"
def get_context_data(self, variable):
return {}
class Media:
css = "style2.css"
js = "script2.js"