Formerly JulioFlores.com - random rambllings about web2py, python, Zope and a bit of C#
Home | web2py | ¿Quién Soy? | Contact Me | Language English |   

Last 10
Older Posts
External Links

Add a Comment

Please keep this blog clean, avoid inflamatory, vulgar or otherwise improper comments. Thanks!

Verify your humanity [94402] Please type in the number shown
Name or Email (OPTIONAL - Names or emails will not be used for any other purpose than contacting the sender)
Message

(Some safe-HTML code is allowed only)

Post Original:

So, you are looking to expand your skills, or perhaps jump ship from the evil Visual Studio into the communist-laden, higher-TCO-development open source evil-er movement, but you are unsure what path to take?

Well my friend, search no more, for your prayers have been answered:

web2py will make you a better person, hmm, that's a little far-feched, maybe a happier programmer would be more appropriate.

If you still don't know what is this all about, I invite you to read a little bit of what we2py is, the main page even includes a "language comparison" and many tips on how to get you up and running in no time.

The framework uses a traditional MVC pattern, where you first define your model (DB abstraction layer, hook-ups and plug-ins), then code the controller and display your page with a view. Every page you hit with your web browser is a controller, or a function in python terms, the controller then calls a view which does the actual visualization/rendering of the page. Take a look at this controller example:

Controller: default.py, defines the "index" function, which will render the "index" view

def index(): """ Main Index Page """ age = 30 name = "John Smith" return dict(name=name, age=age)

View: index.html

{{extend 'layout.html'}} <!-- Contains your "master" layout //--> <h2>Hello {{=name}}</h2> <p>Your Age is {{=age}} years old, in about a year, you will be {{=(age + 1}} years old, isn't that scary?</p> {{if age < 21:}} <p>You are a kid!</p> {{pass}}

And yes, yet another templating system, but hear this from one that come from the ZPT realm, web2py is easy, non-obtrusive and easy to code on.

You can even "code" all your html markup in your controller, by using what is called html helpers in web2py, this means that you can embed html code in your controller by constructing your markup using python functions, consider the following example:

Controller: default.py

def index(): page_info = DIV('Hello', ' ', 'World', _id='hellomsg', _class='info') return dict(page_info=page_info)

View: index.html

{{extend 'layout.html'}} <!-- Contains your "master" layout //--> {{=page_info}}

This will in turn render <div id="hellomsg" class="info">Hello World</div>

Now I do not personally (or necessarily) accept this pattern of coding, and will suggest using it sparingly in your projects. The mixing of markup (presentation) and code (logic) should be avoided as much as possible, note the as much as possible mention, what bothers me a little bit is that web2py is relying on this pattern a little bit too much if you ask me, for example, it makes the creation of your forms and fields (that will eventually tie up to a database field) way too easy, the problem that I see with this approach is this:

Suppose you have this nice controller (remember? a .py python source code file), which contain form, paragraph, classes, ids, and a myriad of markup code in it, and the view (the ultimately rendered HTML code) containing only a {{=big_html_generated_in_python}} variable, at is all good and dandy until the business (because you work at a big business, don't you?) decides to change the entire layout, moving fields around your form, etc, who will have the task of making the changes? the software engineer?? or the html code monkey??, there is a reason for this separation.

Needless to say, I am impressed with this web app development platform, and hope that its user base keeps growing as it appears to be happening now, best to python and web2py.


 
Proudly Powered by Python

TechFuel.net | Web Standards xhtml 1.1 and css 2.1 | Rel 14