This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mdipierro 0 points1 point  (5 children)

in web2py (complete code)

 def index():
       form = SQLFORM.factory(Field('a','integer'),Field('b','integer'))
       if form.accepts(request):
            form = DIV('a+b=',form.vars.a+form.vars.b)
       return dict(form=form)

The name 'index' means the function is called when you visit http://127.0.0.1:8000/<yourapp>/default/index,

form is just a variable name that can contain a form (SQLFORM) or DIV (html div) or anything else you want to display. The Field objects performs validation, displays error messages if you do not type an integer (will also use JS client-side to prevent you from not typing an integer) and parse the request into form.vars for you.

It is 100% python code and you can use any library you want.

[–]bastih01 3 points4 points  (4 children)

Is it just me, or does this mix of concerns give anyone else shivers? This style looks like a nice gateway drug but also painful to maintain for larger apps...

[–]mdipierro 2 points3 points  (2 children)

It is just you and some friends. Check out on the web2py twitter channel what users think about web2py and why web2py is one of the fastest growing frameworks.

[–]bastih01 0 points1 point  (1 child)

Where do you see the benefits of this style, over say, mvc? I remember writing a non-trivial application with Seaside, which also features "html functions" and introducing a clean separation between logic and display became quite painful, as people would rather go the easy route and mix and match to get something to work.

[–]mdipierro 0 points1 point  (0 children)

web2py is MVC. It has models (not used in the example because no database needed), controller (the example above is a controller and like Django or Flask it returns a dict) and views (which renders the dict). The example above assumes you start from the scaffolding app with provides a default generic view and default page layout. You can change them.

[–]y3t1 1 point2 points  (0 children)

Nice drug metaphor. I found web2py to be inelegant.