当前位置:网站首页>Using the flask framework to write the bezel
Using the flask framework to write the bezel
2022-06-11 19:58:00 【Find bug's master】
flask The framework has many functions , So today, let's talk about the application in baffle . First, let's talk about the baffle , This word is commonly used in performance testing , That is, the complete test environment has not been completed , Or the cost of testing is high , Such as sending text messages . Then you need to simulate some functions that are not built or costly , This can be done with a baffle , Intuitively, it is to simulate the real environment .
We also have a certain understanding of the baffle , So how to build it , Then follow me , Build a simple baffle
One 、 open python Editor , Here, I use pycharm, Create a project , Whatever it's called , Build one inside run.py

Two 、 Edit code , There needs to be flask Basic students , If you don't have one, you can read my previous post about flask Framework Basics
from flask import Flask, session, request, redirect, url_for,Response, jsonify
import json
import time
app = Flask(__name__)
# Define the interface path
@app.route('/api/login', methods=['post', 'get'])
def do_login():
# The way to judge a request is post still get
if request.method == "GET":
fail = {
"timestamp": (time.asctime()),
"error": 1
}
# get Return if requested fail data
return jsonify(fail)
# post Return if requested success data
else:
success = {
"data": {
"user_info": request.get_json()["user_info"],
"password": request.get_json()["password"]
},
# Time stamp
"timestamp": (time.asctime()),
"success": 1
}
# return json Data in form
return jsonify(success)
if __name__ == '__main__':
app.run(debug=True)3、 ... and 、 Run code

Okay , Such a simple baffle server is OK , It's very simple , Compared with formal business, there is no complicated business processing process , It is a simple process of simulating the return message , Next, let's use requests Let's test it , See how it works
newly build test.py file

Write the code inside
import json
import requests
# GET request
# requests.get(url, params=None)
# POST request
url = "http://127.0.0.1:5000/api/login"
data = {
"user_info": "xiaoli",
"password": "123456"
}
# Request header , Here's the message json data , So choose the following form
headers = {'Content-Type': 'application/json'}
# Convert a common dictionary type to json type
data_json = json.dumps(data)
# among data Parameters are the data sent , That's our json Type data
res = requests.post(url, data=data_json, headers=headers, json=None)
print(res.text)Run below , Love once , Take a look at the returned results

The above return indicates that our baffle configuration is successful . In this way, we can return the specified return content as required , Specifically, on this basis, it is OK to modify
边栏推荐
- Explanation of LNMP architecture source code compilation and installation with pictures and texts (with forum experiment)
- QQ贴吧那种图片一点开,就变了的原理
- 【四川大学】初试复试考研资料分享
- Hdu3527 (Hangdian) spy problem
- Usage of duck beak wire stripper
- 2022年最新宁夏建筑八大员(标准员)考试试题及答案
- 构建Web应用程序
- 谷歌提出超强预训练模型CoCa,在ImageNet上微调Top-1准确率达91%!在多个下游任务上SOTA!...
- [help] how can wechat official account articles be opened in an external browser to display the selected messages below?
- Yolov3 pytoch code and principle analysis (I): runthrough code
猜你喜欢

Database introduction

计算926的9260次方里的字符串里有多少个926

AHB_Bus_Matrix_3x3 设计

Leetcode2027. Minimum number of operations to convert a string (yes, once)

unity里面使用opencv,qt建立plugin(一)

Yolov3 pytoch code and principle analysis (II): network structure and loss calculation

这些考研专业容易混淆,搞错就白考啦!

POJ 1458 longest common subsequence (dynamic planning exercise)

556. 下一个更大元素 III-(31. 下一个排列)-两次遍历
【求助】请问如何让微信公众号文章在外部浏览器中打开后还能显示下方的精选留言?
随机推荐
dried food! Information diffusion prediction based on sequence hypergraph neural network
C#深拷贝
MySQL - transaction
Raki's notes on reading paper: learning fast, learning slow: a general continuous learning method
AHB2APB_bridge 设计
上海内推 | 上海期智研究院于洋老师课题组招收全职研究员
[Lao Wang's fallacy of brain science] Why do blind people "seem" to be more "sensitive" than normal people?
"Video version Mae" of hekaiming team, efficient video pre training! The effect is also very good when mask ratio is up to 90
STC 纯硬件自动下载电路 V2
Xmake help 2
The tutor transferred me 800 yuan and asked me to simulate a circuit (power supply design)
Template and requirements of curriculum design of reinforced concrete structure in autumn 21 of Dagong [standard answer]
Picture bed: picgo+ Tencent cloud +typera
Google proposed the super pre training model coca, and the accuracy of fine-tuning top-1 on Imagenet reached 91%! SOTA! On multiple downstream tasks
Leetcode2027. Minimum number of operations to convert a string (yes, once)
Flutter--Button浅谈
激活函数公式、导数、图像笔记
构建Web应用程序
STL application (unfinished
A Mechanics-Informed Artificial Neural Network Approach in Data-Driven Constitutive Modeling 学习