Dom
The DOM string returned by the render_function
of Component
and Layout
are wrapped under some custom tags. But in case you want the plain DOM to be streamed then this class comes into picture.
The Dom Class
Dom
is a class that holds the information which is used for rendering it on client. To be more precise, it stores the function and arguments that when called returns the DOM string which needs to be rendered on client.
class flasksr.Dom(render_function, *args, **kwargs)
Parameters:
render_function
: is the function that returns the DOM String. In case there are anyargs
orkwargs
to therender_function
, you can directly pass them into constructor ofDom
. Thus we say that, the constructor also acceptsargs
andkwargs
which are passed directly to therender_function
.
Sample Dom
object: menu
def render_menu():
return """
<ul style="list-style-type: none; margin: 0; padding: 0;">
<li><a href="/">Home</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">About</a></li>
</ul>
"""
d = Dom(render_menu)