Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8299719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:15:57+00:00 2026-06-08T16:15:57+00:00

In the web2py book we see this code def first(): form = SQLFORM.factory(Field(‘visitor_name’, requires=IS_NOT_EMPTY()))

  • 0

In the web2py book we see this code

def first():
    form = SQLFORM.factory(Field('visitor_name', requires=IS_NOT_EMPTY()))
    if form.process().accepted:
        session.visitor_name = form.vars.visitor_name
        redirect(URL('second'))
    return dict(form=form)

being used in a template like so:

{{extend 'layout.html'}}
What is your name?
{{=form}}

And the question becomes: normally python values like strings and numbers are passed in the dictionary to the template engine. But what is being passed in this case and what is it about web2py that allows it to “unroll” it into HTML?

Can I build DOM trees and pass them? Or is this just a big escaped string?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:15:59+00:00Added an answer on June 8, 2026 at 4:15 pm

    In this case, the FORM object (class) is being passed. FORM is a gluon.html object, as are DIV, SPAN, P, etc. They all have a method called “.xml” which ‘unrolls’ the class into an HTML appropriate repsentation.

    In web2py, you can pass any object in the dict() at the end of the controller, and use it in the template. Because web2py uses pure python in templates, you don’t have to make sure your object is “supported” in any way, any object or primitive can be sent. But, HTML objects should inherit from the base class of all HTML objects and should have an .xml() method which represents the object.

    You can pass a dom tree as you put it, assuming you mean a snippet of HTML (hierarchically structured in code). For example:

    some_text = 'even variables'
    
    x = DIV(
      A(IMG(_src='some-img.png'), _href='http://some.link.com/awdawd'),
      SPAN('Some text for whatever reason', _class='my-class', _some_other_html_attribute='i automatically get made into an attribute in the html, via gluonic magic'),
      DIV('I am text, because I am a div, any number of arguments can be combined', 'and displayed', some_text, **{'_data-special-attr':'even-html5-microdata-is-doable'}),
      UL(LI('lists are cool too'), LI('I guess')),
      TABLE([['some objects', 'are smart'], ['and you can pass them lists of lists'], ['and they know what to do with it']])
    )
    
    return dict(content=x)
    

    Is totally valid and will ‘unfold’ properly [assuming I typed it correctly…]

    For more, visit the epydocs: http://www.web2py.com/examples/static/epydoc/web2py.gluon.html.XmlComponent-class.html

    There’s the “base HTML class” i mentioned — it’s actually called XMLComponent.

    here’s the select class:

    http://www.web2py.com/examples/static/epydoc/web2py.gluon.html.SELECT-class.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a simple FORM (not SQLFORM) in web2py with two fields
I was going through http://web2py.com/book/default/chapter/02 and found this: >>> print 'number is ' +
I have this model in web2py DAL: db.define_table('category', Field('name','string'), format='%(name)s' ) db.define_table('uploaded_question', Field('text','string'), ...
While reading the web2py manual, I came across this following: 'Once a new user
I have a fairly simple web2py form with a few validators like, IS_FLOAT_IN_RANGE(...) on
How do i specify the class of a custom web2py form? for e.g. {{=form.custom.begin}}
In a web2py view, how do I comment out server-side code? In ASP.NET, I
I want to Web2py to just return the error screen/stack-trace... i don't want this
I am writing a web2py application that requires summing dollar amounts without losing precision.
In web2py, is there a way to have a piece of common code be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.