Web.py is a simple web frame work that is written in python for the development of python related web applications.The main feature about web .py is that it is very simple and efficient compared to others
Installation:-
- Download web.py from the below link.Then extract and copy it into to any directory that your application resides or make it accessible to all applications.
- Type "cd" in Terminal to "change the directory "where you copied web.py, If you list the contents you can see a setup.py file inside it. To install the file type the below command.
python setup.py install.
- when you found any permission denied messages when installing in unix like systems,switch to root user and then try the below command.
sudo python setup.py install
Working:-
when you installed it properly you can try it by creating some simple webpages.Open any of your favorite editor and creating a file named "hello.py" as shown below.
import web
urls = (
'/', 'hello')
app = web.application(urls, globals())
class hello:
def GET(self):
return 'Hello, web!'
if __name__ == "__main__":
app.run()
Here first you need to import the module web.py to use the tools provided by web.py i.e the first line actually refers.
In the second line we are actually mapping the web address(URL) i.e "http://webpy.org/" to a python class named "hello".
Inside the class you can see a function named "GET()".This function "GET()" is actually displays the content in your browser when your browser opens a web page.Here it will display the string "Hello,web" .
In the third line we are creating an instance .It will handle the all duties like handling the browser request and serving the desired pages.
The last line will start the web application to handle your requests.
Save the above file and run by using the command python hello.py.
when you run the file,the output will be the address of your website ,by default it is (http://localhost:8080/). when you copy it and paste it in your browser search bar you will get the resultant web page.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.