Get the App
SLTechnology News&Howtos  ›  Development  › 

How to install python script Framework webpy

Shulou Source: shulou.com Published: 2022-06-02 13:21:11 10月25日 Update

This article introduces the knowledge about "how to install python script framework webpy". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

One: install pip install web.py Two: URL processing

The most important part of any website is its URL structure.

urls=('/',' Index',) #defines a mapping rule that sends requests for the virtual path '/' to the Index class for processing.

III: Category

Defines an Index class to handle requests for '/', which can be handled according to their own requirements, which may be GET,POST...

class Index: def GET(self): return 'Hello, everyone' 4: Create an app=web.application (urls,globals()) #Create app object app.run() #Launch app 5: instance import web#basic elements of the web #1.urls routing table #2. a web.application instance app#3. startup appurls are url mapping rules, similar to (servert) mapping urls=('/',' Index')#This sentence means that the request sent to the virtual path ' / ' is handed over to the Index class to handle #This url variable designs a URL control scheme for the entire website #Define an Index class to handle routing class Index: def GET(self): #Prevent Chinese garbled characters web.header('Content-Type','text/html;charset=UTF-8') #Your operation can return str, file,html # return "get request! " # return open(r'F:\GitHub\Python\MyWeb\tesseract.log') return 'GET request' def POST(self): return 'post request! '#Create an app=web.application(urls,globals())#The urls parameter indicates a mapping between the url of the website and the functions executed by the application, but you can see that urls is a tuple, and only the string #globals() in the tuple will return a dictionary-like object containing all variables, functions, classes, and modules in the current space. The key is the name of these things, and the value is the response object, so that you can get the object by name. if __name__ == '__main__': app.run ()"Python script framework webpy how to install" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Processing objects websites applications frameworks scripts content functions variables instances more knowledge rules paths routing practical important learned next things Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple MySQL Huawei Xiaomi