python后端接收数据_python后端开发使用flask接收前端数据,处理后返回结果
from flask import Flask, request
import json, time, datetime
import pysolr
import pandas as pd
'''
使用request接收前端post請求
直接使用return發(fā)送后端處理好的數(shù)據(jù)給前端
'''
#flask服務(wù)啟動,進(jìn)行初始化
app = Flask(__name__)
#通過python裝飾器的方法定義一個路由地址,如http://127.0.0.1/test就是接口的url
@app.route('/test', methods=['GET','POST'])
def get_data():
if request.method == 'POST':
argsJson = request.data.decode('utf-8')
argsJson = json.loads(argsJson)
print(argsJson)
result = process_json(argsJson)
result = json.dumps(result, ensure_ascii=False)#轉(zhuǎn)化為字符串格式
return result#return會直接把處理好的數(shù)據(jù)返回給前端
else:
return " 'it's not a POST operation! "
def process_json(data):
return data
if __name__ == '__main__':
app.run(hose='xxx.xxx.xxx.xxx', port=xxxx)#可以設(shè)置為本機IP,或者127.0.0.1
本文地址:https://blog.csdn.net/tailonh/article/details/108865408
如您對本文有疑問或者有任何想說的,請點擊進(jìn)行留言回復(fù),萬千網(wǎng)友為您解惑!
總結(jié)
以上是生活随笔為你收集整理的python后端接收数据_python后端开发使用flask接收前端数据,处理后返回结果的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何用python编一个扫雷游戏_用 P
- 下一篇: 用Python写个小程序,Excel内合