django_unicorn.components.unicorn_template_response
#
Module Contents#
- django_unicorn.components.unicorn_template_response.EMPTY_ELEMENTS = ('<area>', '<base>', '<br>', '<col>', '<embed>', '<hr>', '<img>', '<input>', '<link>', '<meta>',...#
- django_unicorn.components.unicorn_template_response.is_html_well_formed(html: str) bool #
Whether the passed-in HTML is missing any closing elements which can cause issues when rendering.
- django_unicorn.components.unicorn_template_response.assert_has_single_wrapper_element(root_element: bs4.element.Tag, component_name: str) None #
Assert that there is at least one child in the root element. And that there is only one root element.
- django_unicorn.components.unicorn_template_response.get_root_element(soup: bs4.BeautifulSoup) bs4.element.Tag #
Gets the first tag element for the component or the first element with a unicorn:view attribute for a direct view.
- Returns:
BeautifulSoup tag element.
Raises Exception if an element cannot be found.
- class django_unicorn.components.unicorn_template_response.UnsortedAttributes#
Bases:
bs4.formatter.HTMLFormatter
Prevent beautifulsoup from re-ordering attributes.
- attributes(tag: bs4.element.Tag)#
Reorder a tag’s attributes however you want.
By default, attributes are sorted alphabetically. This makes behavior consistent between Python 2 and Python 3, and preserves backwards compatibility with older versions of Beautiful Soup.
If empty_boolean_attributes is True, then attributes whose values are set to the empty string will be treated as boolean attributes.
- class django_unicorn.components.unicorn_template_response.UnicornTemplateResponse(template, request, *, context=None, content_type=None, status=None, charset=None, using=None, component=None, init_js=False, **kwargs)#
Bases:
django.template.response.TemplateResponse
An HTTP response class with a string as content.
This content can be read, appended to, or replaced.
- render()#
Render (thereby finalizing) the content of the response.
If the content has already been rendered, this is a no-op.
Return the baked response instance.