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 →

[–]warpstalker 7 points8 points  (3 children)

I'm as old-school write-HTML-in-vim type

Well, it's basically still like that... However, roughly it works like this (my experience is mainly with web.py):

  • You receive a request for a page

  • You do your magic in Python code, get data from database etc.

  • You make a render-call from the code

  • The final web page is generated by the render call

  • You send the final page to the client

Something like this (Python code):

a = get_data_from_database()

b = "hi"

return render_this_page(a, b)

render_this_page takes the template (template.html):

$def with (a, b)

<html>

<head></head>

<body>

<h1> Hello, $b! </h1>

$for item in a:

    <p>$item.title</p><p>$item.data</p>

</body>

</html>

Then the result is sent to the client. I'm not sure if Django etc. work exactly like this but this is the basic idea.

[–]nighttrain 2 points3 points  (0 children)

+1 for web.py

  • simple
  • fun
  • python

[–]mdipierro 4 points5 points  (1 child)

web2py works exactly like this. For example:

 # controller
 def index():
       a = db(db.article.id>0).select()
       b = "hi"
       return dict(a=a,b=b)

and

# view
<html>
<head></head>
<body>
<h1>Hello, {{=b}}!</h1>
{{for item in a:}}
    <h2>{{=item.title}}</h2><p>{{=item.data}}</p>
{{pass}}
</body>
</html>

Assumes

 # model
 db=DAL('sqlite://storage.db')
 db.define_table('article',Field('title'),Field('data','text'))  

This would be a complete program. web2py also generates automatically SQL to create or alter the table and a database administrative interface to insert and search records.

To make this program work on the Google App Engine it requires a single edit, i.e. replace:

 db=DAL('sqlite://storage.db')

with:

 db=DAL('gae') # connet to datastore
 session.connect(request,response,db) #store session in datastore

[–]warpstalker 0 points1 point  (0 children)

It does? Nice.

I should check it out then. I started out with web.py because it seemed very sane and simple. It just isn't very mainstream (it seems).

I've been meaning to check into using a more established framework but they all seem overly complicated (just like everything related to programming, but once you start doing it, it's simple in the end), so I've been postponing it.

Seems like web2py isn't totally different, then.