User:Simha0994/sandbox

Web.py is a free and open source Web application framework that is as simple as it is powerful.

The web.py slogan is: "Think about the ideal way to write a web app. Write the code to make it happen." . The goal of web.py is to build the ideal way to make web apps. web.py allows the user to build HTTP responses instead of exposing Python objects. In web.py, database can be accessed easily as the framework makes database look like an object. Also, the template system in web.py helps the user to bring Python into HTML.

History
web.py was originally published while Aaron swartz worked at reddit.com, where the site used it as it grew to become one of the top 1000 sites according to Alexa and served millions of daily page views. The site was rewritten using other tools after being acquired by Condé Nast.

Installation
To install web.py on Linux based operating system, wget http://webpy.org/static/web.py-0.37.tar.gz tar -zxvf web.py-0.37.tar.gz cd web.py-0.37/ sudo python setup.py install
 * Firstly, download the following tar file:
 * Extract the downloaded tar file:
 * Go to web.py-0.37 directory:
 * Install and make it accessible to all the applications:

Web.py skeleton
Every web application needs a skeleton. A sample skeleton of web.py application looks as follows.


 * doc: Documentation of all the files.
 * licenses: All the licenses of the project and the libraries used in the application.
 * requirements: Specifying the third party libraries.
 * sh: bash script files of the project.
 * www: The required web application itself.
 * app: contains the application modules.
 * controllers: This module contains the handler modules of controller package.
 * tools: Tools that are used for the project.
 * views]: Template files.
 * models: Database models of the application.
 * bridge: It is used to communicate with the server which is written in another language.
 * lib: The library files developed for the project. These are different from the tools mentioned in the app. Libraries can be used in other projects where as tools are limited to the project itself.
 * public: This folder contains the minimized compiled CSS, Javascript, CoffeeScript files and images so the files in this folder are production ready and can't be used in development.
 * static: Contains the development CSS, CoffeeScript, Javascript, and images files of the project.
 * test: These are the test files.
 * tmp: Garbage files.
 * main.py: These are the only files that are directly executed by the server.
 * main_development.py: Main executable file in development mode.
 * settings.py: Global constants and settings of the application.
 * urls.py: Contains URL's of the application

Features of web.py
web.py has two unique features.

Databases
The database package lets the user access various different databases. Accessing different databases refers to connecting multiple databases. However, its not an ORM. It is similar to sqlite3 package which doesn't use ORM. This feature is missing in Django (another web framework). web.py has flexible modules which allow the user to wipe it out completely and use with another web framework. Before creating database object, the user must install appropriate database library like psycopg2 for PostgreSQL, MySQLdb for MySQL and sqlite3 for SQLite. Working with more databases is not at all difficult with web.py which is explained by the following example: db1 = web.database(dbn='postgres', db='dbname1', user='username1', pw='password2') db2 = web.database(dbn='postgres', db='dbname2', user='username2', pw='password2')

Forms
A forms package is present in web.py which let's the user create forms and validators. The form module of web.py allows the ability to generate html forms, get user input, and validate it before processing it or adding it to a database. But it doesn't have built-in protection against CSRF. A sample login form is as follows: login = form.Form(   form.Textbox('username'),    form.Password('password'),    form.Button('Login'), )

Another interesting feature about web.py is its flexibility. It has flexible modules which can be used with another framework.

Hello world example
import web urls = (	'/', 'index'	)

class index: def GET(self): return "Hello, ECE517!"

if __name__ == "__main__": app = web.application(urls, globals) app.run

If the above example is considered, then the user start the application by importing the web.py module using the following command import web

The most important part of the website is its URL structure. web.py makes it easy to make great URLs.

urls = ( '/', 'index' )

The first part is a regular expressions that matches a URL, like /, /help/faq, /item/, etc. The parantheses are used to intimate about the data to be matched. The second part is the name of a class to send the request to, like index, view, welcome, hello (which gets the hello ECE517 of the welcome module), or get_\1. \1 is replaced by the first capture of the regular expression; any remaining captures get passed to function.

At the top of each application, the user usually see the full URL dispatching scheme defined as a tuple. urls = (   "/tasks/?", "signin",    "/tasks/list", "listing",    "/tasks/post", "post",    "/tasks/act", "actions",    "/tasks/signup", "signup" ) The format of this tuple is: url-path-pattern, handler-class this pattern will repeat as more url patterns are defined.

Conclusion
web.py is a minimalist framework whose aim is not to abstract away the details of interacting with the Web, but to make that interaction easier. It is designed in such a way that user will get started quickly with web.py and find writing HTTP GET function handlers directly. Likewise, the web.py database system does not abstract away SQL rather than hide the fact that the user is querying a database. It hides the details of working with different databases. The framework of web.py is light, photonic when compared to frameworks like flask.