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:

  1. Top menu
  2. Blog Content
  3. Comment Section
  4. Author details
  5. 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 page
  • render_function: is the function that returns the DOM String for this component on the client. In case there are any args or kwargs to the render_function, you can directly pass them into constructor of Component. Thus we say that, the constructor also accepts args and kwargs which are passed directly to the render_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')

results matching ""

    No results matching ""