Component
A web page is divided into number of independent components which are represented by class Component
. A Component
belongs to a Layout
.
Suppose you are creating blog and on the blog page can be divided into following components:
- Top menu
- Blog Content
- Comment Section
- Author details
- Footer
Each part of your page becomes a Component
and the over structure of your page becomes your Layout
.
The Component Class
Component
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 will then be used to render that component on client.
class flasksr.Component(component_id, render_function, *args, **kwargs)
Parameters:
component_id
: uniquely identifies the component in your pagerender_function
: is the function that returns the DOM String for this component on the client. In case there are anyargs
orkwargs
to therender_function
, you can directly pass them into constructor ofComponent
. Thus we say that, the constructor also acceptsargs
andkwargs
which are passed directly to therender_function
.
Sample component: top-menu
def render_top_menu(user_name):
return """
<ul>
<li>%s</li>
</ul>
""" % (user_name)
c = Component('top-menu', render_top_menu, 'arpitbbhayani')