How i found it: In Multiwidget I use CKEditorWidget(forms.Textarea), whose
have own render.
How to reproduce error:
Put MyWidget like a subwidget in multiwidget.
{{{
Class MyWidget(TextInput):
def render(self, *args, **kwargs):
print('hello world')
return super().render(*args, **kwargs)
}}}
Nobody can see "Hello world" after Multiwidget render.
How i patch it - add subwidget.render call in context.
{{{
# in Multiwidget:
def get_context(self, name, value, attrs):
...
context['widget']['subwidgets'] = (self.rednder_subwidget(subwidget,
**subwidget_context) for subwidget, subwidget_context in zip(self.widgets,
context['widget']['subwidgets']))
...
# add
@staticmethod
def rednder_subwidget(subwidget, **kwargs):
kwargs['render'] = lambda:
mark_safe(subwidget.render(kwargs['name'], kwargs['value'],
attrs=kwargs['attrs'], renderer=kwargs.get('renderer')))
return kwargs
in multiwitget template:
{% spaceless %}{% for widget in widget.subwidgets %}{{widget.render}}{%
endfor %}{% endspaceless %}
}}}
Other possibility - write in documentation: MultiWidget works only with
native Built-in Django widgets.
--
Ticket URL: <https://code.djangoproject.com/ticket/33445>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* cc: Matthias Kestenholz, David Smith (added)
* type: Bug => New feature
* easy: 1 => 0
* has_patch: 1 => 0
* resolution: => needsinfo
Comment:
Thanks for this report, however it's not a bug, IMO. `MultiWidget` is also
a normal `Widget` and getting context for subwidgets (as
[https://docs.djangoproject.com/en/4.0/ref/forms/widgets/#django.forms.MultiWidget.get_context
documented]) should be sufficient for rendering. `render()` is a highly
specialized method and I don't see why calling a custom `render()` for
subwidgets would be necessary. Also, as far as I'm aware
[https://github.com/django-ckeditor/django-
ckeditor/blob/50cd4aba9533c541e7d1ef5a4e67aed8c827f10c/ckeditor/widgets.py#L28-L137
CKEditorWidget] doesn't have a `render()` method.
What's your use case?
--
Ticket URL: <https://code.djangoproject.com/ticket/33445#comment:1>