পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Friday, March 17, 2017

Web2py - Components

A component is defined as the functional part of a web page, which works autonomously. It can be composed of modules, controllers and views, which are embedded in a web page. The component in an application, must be localized tag and the performance is considered to be independent of module.
In web2py, the main focus is on using components that are loaded in page and which communicate with the component controller via AJAX.

web2py includes a function, which is called the LOAD function, which makes implementation of components easy without explicit JavaScript or AJAX programming.
Consider a simple web application namely “test” that extends the web2py application with custom model in file “models/db_comments.py”.
db.define_table(
   'comment_post', Field('body','text',
   label = 'Your comment'),auth.signature
)
The above code will create a table “comment_post” with the proper table definition. The action will be implemented with the help of functions in “controllers/comments.py”.
def post():
   return dict(
      form = SQLFORM(db.comment_post).process(),
      comments = db(db.comment_post).select()
   )
The corresponding view will be displayed as −
{{extend 'layout.html'}}
{{for post in comments:}}

<div class = "post">
   On {{= post.created_on}} {{= post.created_by.first_name}}
   says <span class = "post_body">{{= post.body}}</span>
</div>

{{pass}}
{{= form}}
The page can be accessed using the given URL − http://127.0.0.1:8000/test/comments/post
The method mentioned above is a traditional way of accessing a view, which can be changed with the implementation of the LOAD function.
This can be achieved by creating a new view with the extension ".load" that does not extend the layout.
The new view created would be "views/comments/post.load"
<div class = "post">
   On {{= post.created_on}} {{= post.created_by.first_name}}
   says <blockquote class = "post_body">{{= post.body}}</blockquote>
</div>

{{pass}}
{{= form}}
The URL to access the page would be − http://127.0.0.1:8000/test/comments/post.load
The LOAD component can be embedded into any other page of web2py application. This can be done by using the following statement.
{{= LOAD('comments','post.load',ajax = True)}}
For example, the Controllers can be edited as −
def index():
   return dict()
In View, we can add the component −
{{extend 'layout.html'}}
{{= LOAD('comments','post.load',ajax = True)}}
The page can be accessed with the URL − http://127.0.0.1:8000/test/default/index

Component Plugins

Component plugins are the plugins, which uniquely define Components. Components access the database directly with their model definition.
As mentioned in the previous example, comments component into a comments_plugin can be done in the Models section −
"models/plugin_comments.py" −
db.define_table(
   'plugin_comments_comment',
   Field('body','text', label = 'Your comment'),
   auth.signature
)
The Controller will include the following plugin −
def plugin_comments():
   return LOAD('plugin_comments','post',ajax = True)

No comments:

Post a Comment