django-sniplates
django-sniplates copied to clipboard
Attempting to render one of the django.html inputs without backing it with a form field errors
Given:
{% widget "form_alias:TextInput" id="lol" raw_value="lol2" %}
An exception is raised:
AttributeError: 'str' object has no attribute 'items'
because {{ widget.attrs|flatattrs }} receives '' (or TEMPLATE_STRING_IF_INVALID maybe? dunno) due to not having a Widget instance in the context.
Probably the fix is to wrap the widget attrs output in an IfNode?
If I remember correctly from the Django docs, filters should fail silently if something goes wrong, so then https://github.com/funkybob/django-sniplates/blob/master/sniplates/templatetags/sniplates.py#L497 should be edited to something like:
@register.filter
def flatattrs(attrs):
if not attrs:
return TEMPLATE_STRING_IF_INVALID
return flatatt(attrs)
@funkybob thoughts?
Actually there's a setting about if a failure should be silent, IIRC.
I think there are some DTL errors that are never swallowed, too.
I think in this case the filter ought default to safe.