Ramblings

March 28, 2008

web2py new website

Filed under: cool, dev, python, web2py — michaelangela @ 4:20 am

Web2py is humming along and just got a redesigned front page. Nice, clean, and accessible. Gotta love the “complex” tutorial. Fits in a page! 🙂

web2py Enterprise Web Framework

A taste of web2py

Consider the following complete application which consists a model (which describes the data representation): db.py

1.
2.
db=SQLDB('sqlite://images.db')
db.define_table('image',SQLField('file','upload'))

a controller (which describes the application logic and workflow): images_examples.py

1.
2.
3.
4.
def index():
form=SQLFORM(db.image)
if form.accepts(request.vars,session): response.flash='image uploaded'
return dict(form=form)

and a view (which describes the data presentation): images_examples/index.html:

1.
2.
3.
{{extend 'layout.html'}}
<h1>Upload page</h1>
{{=form}}

What does it do?

  • Creates the database db in file ‘images.db’
  • Creates the table ‘image’ which contains a field called ‘file’. If
    the table exists but does not match the definition it is altered
    accordingly.
  • Creates a web-based database administrative interface for db.image
  • Creates a web page called index with upload form for db.image. Try it here
  • On upload the file is renamed in a secure way, saved, and the name of the file is stored in a new field db.image record.
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: