Flask application

1. In Pycharm's new falsk project, the directory structure is as follows :
Insert picture description here
app.py is the entry program, there is also a static static directory, templates is the location where templates are stored.

2. The code in the original app.py is as follows :
Insert picture description here
Description: The
Flask module must be imported into the project. One object of the Flask class is our WSGI application. The Flask constructor uses the name of the current module (__name__) as a parameter.

The route() function of the Flask class is a decorator that tells the application which URL should call the related function.

app.route(rule, options) # rule 参数表示与该函数的URL绑定;options 是要转发给基础Rule对象的参数列表。

In the above example, the'/' URL is bound to the hello_world() function. Therefore, when the homepage of the web server is opened in a browser, the output of this function will be presented.

Finally, the run() method of the Flask class runs the application on the local development server.

app.run(host, port, debug, options) #所有参数都是可选的

Insert picture description here
Three, debugging mode

Start the Flask application by calling the run() method. However, when the application is under development, it should be restarted manually for each change in the code. To avoid this inconvenience, please enable debugging support. If the code changes, the server will reload itself. It will also provide a useful debugger to track errors in the application (if any).

Before running or passing debugging parameters to the run() method, enable Debug mode by setting the debug property of the application object to True.

app.debug = True
app.run()
app.run(debug = True)

Guess you like

Origin blog.csdn.net/baidu_24752135/article/details/114444336