Python beginner webpy small application development

  • 2021-11-14 06:09:31
  • OfStack

web. py is a lightweight Python web framework that is simple and powerful.

web. py is an web framework for Python, which is simple and powerful. web. py is public and is unlimited for any purpose. And it is quite small, so it should belong to the lightweight web framework.

Install webpy first using pip/pip3


pip install web.py

The latest version 0.61 requires Python > = 3.5
Version 0.51 requires Python 2.7
This is an example of getting started app. py


import web

urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello:
    def GET(self, name):
        if not name:
            name = 'World'
        return 'Hello, ' + name + '!'

if __name__ == "__main__":
    app.run()

Start the run command:


python3 app.py

The default port bit is 8080, and the browser accesses http://0.0. 0.0: 8080/

The project begins to prepare requirements. txt web. py = = 0.62 and then begins to write our first template


#!/usr/bin/python 
# -*- coding:utf8 -*- 
import web,os
urls = ('/','index')
render = web.template.render('templates/')

class index:
    def GET(self):   
        name = ' Millennium code farmer ' 
        return render.index(name)

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

Project source code address: https://gitee.com/shuogesha/py_flash


Related articles: