当前位置:网站首页>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)
- 556. 下一个更大元素 III-(31. 下一个排列)-两次遍历
- Web3 product manager guide - Jason
- Detailed tutorial on installing MySQL database in Linux environment (including uninstallation and password reset process)
- [bug resolution] unpickingerror: a load persistent ID instruction was encoded, but no persistent_ load.
- Full list! 2022 Times Asia University Rankings announced!
- Xmake help 2
- MySQL——基本的Select语句
- Interpretation of OCP function of oceanbase Community Edition
- 接口隔离原则
猜你喜欢
【求助】请问如何让微信公众号文章在外部浏览器中打开后还能显示下方的精选留言?

干货!基于序列超图神经网络的信息扩散预测

AHB_ Bus_ Matrix_ 3x3 design

Qubicle notes: self set shortcut keys (attached with Lao Wang's self set shortcut key file)

Picture bed: picgo+ Tencent cloud +typera

Interface isolation principle

POJ 1458 longest common subsequence (dynamic planning exercise)

In 2021, the global revenue of Indian fragrant rice was about $12530 million, and it is expected to reach $21670 million in 2028

Summary 111111111111111111111

The first bullet of comparative learning
随机推荐
VS2010 cannot open when linking sql2008 database
[high precision] decimal integer addition
28. JS执行机制
29. Objet de localisation
管理者必须知道的三个常识
Picture bed: picgo+ Tencent cloud +typera
Interface isolation principle
Xmake help 2
My favorite product management template - Lenny
"Video version Mae" of hekaiming team, efficient video pre training! The effect is also very good when mask ratio is up to 90
周鸿祎:想做直播带货抹不下面子 数据勒索成突出的安全威胁
STL application (unfinished
556. 下一个更大元素 III-(31. 下一个排列)-两次遍历
The latest test questions and answers for the eight major members (standard members) of Ningxia architecture in 2022
STC 纯硬件自动下载电路 V2
The first bullet of comparative learning
QQ贴吧那种图片一点开,就变了的原理
Detailed explanation on persistence of 2022redis7.0x
3D建模有什么技巧吗?
Template and requirements of curriculum design of reinforced concrete structure in autumn 21 of Dagong [standard answer]