def process_response(self, request, response): doctype = getattr(response, 'doctype', None) if doctype is None: doctype = getattr(settings, 'DOCTYPE', 'xhtml1') if doctype in html_doctypes: response.content = clean_html(response.content, doctype) return response
def render(self, context): field = template.resolve_variable(self.field_var, context) # Caling bound_field.as_widget() returns the HTML, but we need to # intercept this to manipulate the attributes - so we have to # duplicate the logic from as_widget here. widget = field.field.widget attrs = self.extra_attrs or {} auto_id = field.auto_id if auto_id and 'id' not in attrs and 'id' not in widget.attrs: attrs['id'] = auto_id if not field.form.is_bound: data = field.form.initial.get(field.name, field.field.initial) if callable(data): data = data() else: data = field.data html = widget.render(field.html_name, data, attrs=attrs) # Finally, if we're NOT in xhtml mode ensure no '/>' doctype = getattr(context, '_doctype', 'xhtml1') return clean_html(html, doctype)