In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use flask to write a web service in python. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.
Flask is a lightweight Web application framework written in Python. Its WSGI toolbox uses Werkzeug, and the template engine uses Jinja2. Flask uses BSD authorization.
Flask is also called "microframework" because it uses a simple core and adds other functions with extension. Flask does not have database and form validation tools that are used by default.
The above is from Baidu Encyclopedia.
Flask's official website: http://flask.pocoo.org/
Please search for the package that installs flask in python
Here is a simple web service code sample for flask:
#-*-coding: UTF-8-*-
# introduce the required development package
Import configparser
From flask import Flask
From flask import request
From flask import Response
Import os
Import json
# initialize a flask object
App = Flask (_ _ name__)
# define the route and implementation method of a service, and return a hello world string
@ app.route ('/ route1/route2')
Def simplesample ():
Return 'hello world'
# the above services can be accessed by entering the http:// host address: Port number / route1/route2 in the browser
# the following route is to create a route with a variable parameter in the path, with route2 as the parameter, which can be passed in on the client.
@ app.route ('/ route1/')
Def simplesample1 (route2):
Return route2
# say hello to the route with parameters after it. When defining it, you don't need to write the parameters in the route, just get it in the code
# http://localhost:2018/route1/route3?param1=param1
@ app.route ('/ route1/route3')
Def simplesample2 ():
Param1 = request.args.get ('param1',')
# corresponding actions
Return param1# executes the operation of app and sets the server address and port number that the service listens to.
If _ _ name__ = ='_ _ main__':
App.run (host='localhost', port='2018')
On how to use flask in python to write a web service is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.