In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "Web micro-framework Flask how to install and use", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Web micro-framework Flask how to install and use" this article.
Foreword:
Flask is a Web micro-framework implemented by Python, which is called micro-framework because the core of Flask is simple and easy to expand, and there are two main dependencies. WSGI toolset: Werkzeug and template engine: Jinja2,Flask only retains the core functions of Web development, other functions are implemented by external extensions, such as integrated database, form authentication, file upload, a variety of open authentication technologies and other functions. It is precisely because Flask allows users to choose extension functions flexibly, Flask is becoming more and more popular among developers.
1. Installation and simple Flask
You can use the pip install flask command to install.
1. Create a sample program
After the installation is complete, let's write a Hello Flask! The sample program of. Create a new Python project and create a new app.py file in the project root directory
Write the following code:
From flask import Flaskapp = Flask (_ _ name__) @ app.route ('/') def index (): return 'Hello flashover clusters if _ _ name__ = =' _ _ main__': app.run () 2. Code decomposition 2.1Instantiates the Flask class from flask import Flaskapp = Flask (_ _ name__) 2.2 registered route @ app.route ('/') def index (): return 'Hello flashover'
Append an app.route () decorator to the function index (), and pass url:/ as a parameter to let url associate with the function). When the user accesses the address /, the index () function is triggered, and this route-bound function is called the view function.
2.3 start the Web server if _ _ name__ ='_ _ main__': app.run ()
When this file is executed directly with the python app.py command, the Web server is started through app.run ().
Executing the flask run command in the command line window can also start the Web server
As follows:
Flask's built-in development server listens to the http:/127.0.0.1:5000 address by default, and when we open a browser to access this address
The following information is displayed:
You can also pass the host=0.0.0.0 and port= port numbers in the run () method to specify the listening host and port number. in addition, you can also set the debug debugging mode
For example:
If _ _ name__ ='_ _ main__': app.run (host='0.0.0.0', port=8080, debug=True)
When you start the Web server with the flask run command, you can specify the listening host and port number by specifying parameters:-- host=0.0.0 0,-- port=8888.
Note: Flask's built-in Web server is mainly for development and debugging, and it is best to deploy it in a production environment using gunicorn+Nginx.
The above is all the contents of the article "how to install and use the Web Micro Framework Flask". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.