websauna.system.core.render module

Rendering helpers.

class websauna.system.core.render.OnDemandResourceRenderer[source]

Bases: object

A JS and CSS resource registry which helps to allow widgets and such add JS and CSS files dynamically on the page.

Usually instance of this class is available as request.on_demand_resource_renderer.

The best practice is to place all JavaScript files before the closing </body> tag, so that they do not block the the page rendering and decrease the page response time. However, out there exist a lot of badly written JavaScript code which does not honour this - they have <script> tags in the middle of <body> and even worse assume you have loaded dependencies, like jQuery, in the <head>. Namely, Deform 2 form library does this.

BodyRelocatableResourceRegistry contains the logic to determine if <script> tags should go to the end of the page (preferred) or to <head> (in case some javascript makes assumptions of this). If any widget requires resources assume JS must go to head.

See also :py:attr`deform.widget.default_resources` which includes the list of default resources activated for any form on the page.

More information


Get list of resource URLs to render.


kind – “js” or “css”

Return type


Return type


request_resource(kind, resource_url, js_requires_head=False)[source]

A widget or something wants to place a CSS or JS file on the page rendering.

  • kind (str) – “js” or “css”

  • resource_path – Resolved full URL to this resource

  • js_requires_head (bool) – Move all JavaScript to <head> instead of </body> end. I.e. you have <script> tags in the middle of HTML.


Reify method for configuration.