当前位置:网站首页>Flash quickly builds an API
Flash quickly builds an API
2022-07-27 12:14:00 【Canghai light boat 690】
AIP It's very common ,flask It's easy to build again , use flask Quickly build a API
install Flask
pip install Flask
Import Flask modular
To write WEB flask
from flask import Flask,jsonify
app = Flask(__name__)
@app.route('/')
def hello_world(): # put application's code here
return 'Hello World!'
if __name__ == '__main__':
app.run(debug=True)
Definition API
@app.route('/api', methods=['POST'])
def home():
T = random.randint(11, 30)
H = random.randint(50, 80)
date_time = datetime.datetime.now()
HongKong = random.randint(5, 20)
GuangZhou = random.randint(5, 20)
datas = [
{
'id': 1,
'T': T,
'H': H,
"Time": 2,
},
]
return jsonify({'datas': datas})
Cross domain
CORS(app, supports_credentials=True)
If there is Chinese
app.config['JSON_AS_ASCII'] = False
Complete code
from flask import Flask,jsonify
app = Flask(__name__)
CORS(app, supports_credentials=True)
app.config['JSON_AS_ASCII'] = False
@app.route('/')
def hello_world(): # put application's code here
return 'Hello World!'
@app.route('/api', methods=['POST'])
def home():
datas = [
{
'id': 1,
'T': T,
'H': H,
"Time": 2
},
]
return jsonify({'datas': datas})
if __name__ == '__main__':
app.run(debug=True)
flask_restful- Flask API Use
http://www.pythondoc.com/Flask-RESTful/extending.html
install flask-restful
pip install Flask-RESTful
The import module
from flask_restful import Resource, Api
To configure AIP application
app = Flask(__name__)
api = Api(app)
class HelloWorld(Resource):
def get(self):
return {'hello': 'world'}
api.add_resource(HelloWorld,
'/',
'/hello')
Complete code
from flask import Flask,jsonify
from flask_restful import Resource, Api
app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
@app.route('/')
def hello_world(): # put application's code here
return 'Hello World!'
app = Flask(__name__)
api = Api(app)
class HelloWorld(Resource):
def get(self):
return {'hello': 'world'}
api.add_resource(HelloWorld,
'/',
'/hello')
if __name__ == '__main__':
app.run(debug=True)
边栏推荐
- 严控室外作业时间!佛山住建局发文:加强高温期间建筑施工安全管理
- Common power supply problems and solutions of Arduino
- Sword finger offer note: T39. Numbers that appear more than half of the time in the array
- JS parasitic combinatorial inheritance
- Multi activity disaster recovery construction after station B 713 accident | takintalks share
- STS下载教程(include官网无法下载解决方案)
- go入门篇 (4)
- Wilcoxon rank sum and signed rank
- Guangdong: fire safety supervision is no longer "absent" in new industries and new formats such as script killing
- [machine learning whiteboard derivation series] learning notes - probability graph model and exponential family distribution
猜你喜欢

go 用本地代码replace

Shell脚本文本三剑客之sed
![[untitled] multimodal model clip](/img/f0/8ae72ae0845372b6fe2866fae83f52.png)
[untitled] multimodal model clip

【机器学习-白板推导系列】学习笔记---概率图模型和指数族分布

严控室外作业时间!佛山住建局发文:加强高温期间建筑施工安全管理

Finding the finite zero point of transfer function under different sampling periods
![[machine learning whiteboard derivation series] learning notes --- conditional random fields](/img/cc/87d8822b659b31360546adf057ef00.png)
[machine learning whiteboard derivation series] learning notes --- conditional random fields

Beyond compare 3 next difference segment / down search arrow not found

Alibaba cloud RDS exception during pool initialization

Could not load dynamic library ‘libcudnn.so.8‘;
随机推荐
V-show failure
源码编译安装LAMP
compute_ class_ weight() takes 1 positional argument but 3 were given
53 亿 BI 市场 TOP 10:帆软、微软、永洪、SAP、百度、IBM、SAS、思迈特、Salesforce、浪潮通软
【机器学习-白板推导系列】学习笔记---支持向量机和主成分分析法
Shell script text three swordsman awk
Leetcode 01: t1. sum of two numbers; T1108. IP address invalidation; T344. Reverse string
About offline caching application cache / using manifest file caching
A possibility that ch340 module cannot be recognized / burned
Adobe audit prompts that the sampling rate of audio input does not match the output device - problem solving
SMA TE: Semi-Supervised Spatio-Temporal RepresentationLearning on Multivariate Time Series
Unity shader - Laser special effect shader[easy to understand]
Weibo comment crawler + visualization
Shell脚本文本三剑客之sed
w.r.t. ; i.e.; etc.; e. G. what does it mean
Sword finger offer notes: t57 - I. and two numbers of S
系统临时文件的写和读:createTempFile和tempFileContent[通俗易懂]
阿里云云数据库RDS版Exception during pool initialization
Synchronous use reference of the new version of data warehouse (for beginners)
Temporary use of solo, difficult choice of Blog