User:Yrathor: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=='''Web.py Introduction'''==
'''Web.py Introduction'''
Web.py is a [https://en.wikipedia.org/wiki/Free_and_open_source free and open source] [https://en.wikipedia.org/wiki/Web_application_framework web application framework] that is as simple as it is powerful. Web.py was originally published while Aaron swartz worked at [http://reddit.com/ reddit.com], where the site used it ass it grew to become one of the top 1000 sites according to Alexa and served millions of daily page views. "It's the anti-framework framework. web.py doesn't get in your way." explained founder Steve Huffman.


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. In web.py, Instead of exposing Python objects, it allows you to build HTTP responses. Instead of trying to make the database look like an object, web.py makes the database easier to use. And instead of coming up with yet another way to write [https://en.wikipedia.org/wiki/HTML HTML], the web.py template system tries to bring Python into HTML.
Web.py is a [https://en.wikipedia.org/wiki/Free_and_open_source free and open source] [https://en.wikipedia.org/wiki/Web_application_framework 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. In web.py, Instead of exposing [https://en.wikipedia.org/wiki/Python_(programming_language) Python] objects, it allows you to build HTTP responses. Instead of trying to make the database look like an object, web.py makes the database easier to use. And instead of coming up with yet another way to write [https://en.wikipedia.org/wiki/HTML HTML], the web.py template system tries to bring Python into HTML.


Some of the sites which uses web.py are
Some of the sites which uses web.py are
Line 9: Line 10:
* [http://makehistory.national911memorial.org/ Make History], a project of the 9/11 memorial museum.
* [http://makehistory.national911memorial.org/ Make History], a project of the 9/11 memorial museum.


=='''Python'''==
=='''History'''==
 
Python is a [https://en.wikipedia.org/wiki/Multi-paradigm_programming_language multi-paradigm programming language]: object-oriented programming and [https://en.wikipedia.org/wiki/Structured_programming structured programming] are fully supported, and there are a number of language features which support functional programming and aspect-oriented programming (including by [https://en.wikipedia.org/wiki/Metaprogramming metaprogramming]). Python uses [https://en.wikipedia.org/wiki/Dynamic_typing dynamic typing] and a combination of reference counting and a cycle-detecting garbage collector for [https://en.wikipedia.org/wiki/Memory_management memory management]. An important feature of Python is dynamic [https://en.wikipedia.org/wiki/Name_resolution_(programming_languages) name resolution], which binds method and variable names during program execution.
 
Ruby's creator, Yukihiro Matsumoto, has said: "I wanted a scripting language that was more powerful than Perl, and more object-oriented than '''Python'''. That's why I decided to design my own language."


The world of Python web frameworks is full of choices. Django, Flask, Pyramid, Tornado, Bottle, Diesel, Pecan, Falcon, web.py, web2py and many more are competing for developer mindshare. The developer needs to cut the options down to one framework depending on the type of application.
Web.py was originally published while Aaron swartz worked at [http://reddit.com/ 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. "It's the anti-framework framework. web.py doesn't get in your way." explained founder Steve Huffman.


=='''Why Web.py?'''==
=='''Why Web.py?'''==
Line 27: Line 24:


=='''Installation'''==
=='''Installation'''==
To install web.py,  
To install web.py on Linux based operating system,  
* Firstly, download the following tar file:
* Firstly, download the following tar file:
  wget http://webpy.org/static/web.py-0.37.tar.gz
  wget http://webpy.org/static/web.py-0.37.tar.gz
Line 36: Line 33:
* Install and make it accessible to all the applications:
* Install and make it accessible to all the applications:
  sudo python setup.py install
  sudo python setup.py install
=='''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: As you can guess easily, 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'''==
=='''Features of web.py'''==


''web.py has two interesting features''
''web.py has two unique features''


===Databases===
===Databases===


The database package lets you access various of different databases. Accessing different databases refers to connecting to multiple databases. However, its not an [https://en.wikipedia.org/wiki/Object-relational_mapping ORM]. This feature is missing in [https://en.wikipedia.org/wiki/Django_(web_framework) Django] (another web framework) from long time. This feature is helpful for the people who are good at SQl and don't like to use SQL as it is similar to sqlite3 package but doesn't use ORM.
The database package lets you access various different databases. Accessing different databases refers to connecting multiple databases. However, its not an [https://en.wikipedia.org/wiki/Object-relational_mapping ORM]. It is similar to sqlite3 package which doesn't use ORM. This feature is missing in [https://en.wikipedia.org/wiki/Django_(web_framework) 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 [https://en.wikipedia.org/wiki/PostgreSQL PostgreSQL], MySQLdb for [https://en.wikipedia.org/wiki/MySQL MySQL] and sqlite3 for [https://en.wikipedia.org/wiki/SQLite SQLite]. Working with more databases is not at all difficult with web.py which is explained by the following example:
<pre>
db1 = web.database(dbn='postgres', db='dbname1', user='username1', pw='password2')
db2 = web.database(dbn='postgres', db='dbname2', user='username2', pw='password2')
</pre>


===Forms===
===Forms===


A forms package is present in web.py which let's us create forms and validators. Ironically, it doesn't have built-in protection against [https://en.wikipedia.org/wiki/Cross-site_request_forgery CSRF]. If you want to create a login form, you can use forms package to create.
A forms package is present in web.py which let's us create forms and [https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Data_form_validation 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 [https://en.wikipedia.org/wiki/Cross-site_request_forgery CSRF]. A sample login form is as follows:
<pre>
login = form.Form(
    form.Textbox('username'),
    form.Password('password'),
    form.Button('Login'),
)
</pre>


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


==Hello world example==
=='''Hello world example'''==
<pre>
<pre>
import web
import web
Line 60: Line 94:
class index:
class index:
def GET(self):
def GET(self):
return "Hello, ECE 517!"
return "Hello, ECE517!"


if __name__ == "__main__":
if __name__ == "__main__":
Line 67: Line 101:
</pre>
</pre>


==Conclusion==
If the above example is considered, then we 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.
 
<pre>
urls = (
  '/', 'index'
)
</pre>
 
The first part is a [https://en.wikipedia.org/wiki/Regular_expression regular expressions] that matches a URL, like /, /help/faq, /item/, etc. The parentheses say to capture that piece of the matched data for use later on. 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 your regular expression; any remaining captures get passed to your function.
 
Web.py's URL handling scheme is simple yet powerful and flexible. At the top of each application, you usually see the full URL dispatching scheme defined as a tuple.
 
<pre>
urls = (
    "/tasks/?", "signin",
    "/tasks/list", "listing",
    "/tasks/post", "post",
    "/tasks/act", "actions",
    "/tasks/signup", "signup"
)
</pre>
 
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 you're querying a database. It hides the details of working with different databases.
 
=='''References'''==
[[#References|[1]]] web.py official website: http://webpy.org/
 
[[#References|[2]]] python development story: http://faruk.akgul.org/blog/python-development-story-why-webpy/


The philosophy of Web.py -- a minimalist framework -- is not to abstract away the details of interacting with the Web, but to make that interaction easier. As a result, you'll find yourself writing HTTP GET function handlers directly. Likewise, the Web.py database system does not abstract away SQL; rather than hide the fact that you're querying a database, it hides the details of working with different databases. Web.py does define a template language, which -- like that of Web2py -- lets you embed arbitrary Python code in a Web page. Web.py is ideal if you're already familiar with building Web applications (perhaps you once wrote CGI-based applications). You'll get started quickly with Web.py, but you'll have to rely on your own wits to go beyond simple Web applications.
[[#References|[3]]] pillars of python-six web frameworks: http://www.infoworld.com/article/2622836/application-development/pillars-of-python--six-python-web-frameworks-compared.html?page=2


==References==
[[#References|[4]]] Django vs flash vs pyramid https://www.airpair.com/python/posts/django-flask-pyramid
[[#References|[1]]] python development story: http://faruk.akgul.org/blog/python-development-story-why-webpy/


[[#References|[2]]] pillars of python-six web frameworks: http://www.infoworld.com/article/2622836/application-development/pillars-of-python--six-python-web-frameworks-compared.html?page=2
[[#References|[5]]] Form Validation: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Data_form_validation


[[#References|[3]]] Django vs flash vs pyramid https://www.airpair.com/python/posts/django-flask-pyramid
[[#References|[6]]] Aaron swartz about web.py http://www.aaronsw.com/weblog/rewritingreddit


* [[Object-Oriented Design and Programming]]
[[#References|[7]]] https://www.wikipedia.org/

Latest revision as of 01:08, 16 February 2016

Web.py Introduction

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. In web.py, Instead of exposing Python objects, it allows you to build HTTP responses. Instead of trying to make the database look like an object, web.py makes the database easier to use. And instead of coming up with yet another way to write HTML, the web.py template system tries to bring Python into HTML.

Some of the sites which uses web.py are

  • Frinki, a new social network in spanish.
  • oyster.com, a website that reviews hotels uses web.py for the entire website.
  • Make History, a project of the 9/11 memorial museum.

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. "It's the anti-framework framework. web.py doesn't get in your way." explained founder Steve Huffman.

Why Web.py?

The reasons for using web.py are

  • Simplicity
  • Freedom
  • writing clean code
  • minimalism
  • a solid web framework

Installation

To install web.py on Linux based operating system,

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

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: As you can guess easily, 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 you 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 us 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 we 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 parentheses say to capture that piece of the matched data for use later on. 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 your regular expression; any remaining captures get passed to your function.

Web.py's URL handling scheme is simple yet powerful and flexible. At the top of each application, you 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 you're querying a database. It hides the details of working with different databases.

References

[1] web.py official website: http://webpy.org/

[2] python development story: http://faruk.akgul.org/blog/python-development-story-why-webpy/

[3] pillars of python-six web frameworks: http://www.infoworld.com/article/2622836/application-development/pillars-of-python--six-python-web-frameworks-compared.html?page=2

[4] Django vs flash vs pyramid https://www.airpair.com/python/posts/django-flask-pyramid

[5] Form Validation: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Data_form_validation

[6] Aaron swartz about web.py http://www.aaronsw.com/weblog/rewritingreddit

[7] https://www.wikipedia.org/