Day 01
Recent projects written in python to use the back end, the students recommended the flask to learn a framework to learn. The main purpose of writing this blog is to record what content they learn, do not forget to have a basic knowledge of one to Baidu, there is to share with you, where there is not very easy to understand Comments can learn new things like this, Society is not to say that can understand, but completely new to people who did not feel this way. Here IDE is not very recommended to use the Community Edition, Professional Edition because you can directly select New Project flask, auto-generated frame-based projects (although the impact is not great).
Chinese New Year at home, learning efficiency is really low, said a lot of nonsense, or remember the point of learning content, incidentally, I wish you all a Happy New Year.
Four open debug mode
-
app.run(debug=True)
-
app.debug=True
-
app.config.update(DEBUG=True)
-
Using the configuration file in two ways: (config.py need to create a file)
1. Use import import using app.config.from_object (config)
2.app.config.from_pyfile ( 'file_name', silent = False), without having to import, the file format may be .py, and the like may be .txt, silent time = False If the file does not exist will be given
Passing parameters
Each app.route represents a view, if the variable needs to be placed in <>, the variables can be "Type: variable name" explicitly specify the type
string type can only accept free \ / string
acceptable path can comprise \ / string
any path can specify multiple
#example for any:
If there is uncertainty parameters, you can pass parameters by a question mark. A plurality of connection parameters between an ampersand.
? # .. / d / WD = ...
url_for function is a very common function, which function is to return a view corresponding path.
Use method: the url_for ( 'endpoint', ** = value), note that this endpoint view function name corresponding to the function, not the end flag to see the name understood as the path, such as a return like '/ d /' of path, endpoint corresponds to 'fun' instead of 'd'
Its advantage is that, when the endpoint corresponding path can be changed individually without looking for changes
#example