mirror of
https://github.com/django-components/django-components.git
synced 2025-12-04 04:01:35 +00:00
Require get_context_data set to accept parameters.
This commit is contained in:
parent
fa3731422f
commit
a2f0e2246b
3 changed files with 12 additions and 2 deletions
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue