Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

python - I get a blank flask page whenever I send a post request, and try a get request. both give me http 200 codes but still do nothing in the flask server

I have been trying to send a json message by a post request (which seems to be working) but when I try to return the data so I can move it with a get request, the page is just blank. I get code 200 every time. here is the flask server:

from flask import Flask,current_app, flash, jsonify, make_response, redirect, request, url_for
import json
app=Flask(__name__)
@app.route('/', methods=["GET"])
def index1():
    return 'hi'
@app.route('/summary',methods=["GET","POST"])
def summary():
    headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
    return request.get_data()
    #return jsonify(request.data,'utf-8')
if __name__=='__main__':
    app.run(port=3000)

Here is the test post request I am posting through postman:

{"user":"abcd"}

Url: http://127.0.0.1:3000/summary

expected GET request data:(in either string or json form) {"user":"abcd"}

http code: POST: 127.0.0.1 - - [04/Feb/2021 12:13:47] "←[37mPOST /summary HTTP/1.1←[0m" 200

GET: 127.0.0.1 - - [04/Feb/2021 12:13:39] "←[37mGET /summary HTTP/1.1←[0m" 200

question from:https://stackoverflow.com/questions/66046356/i-get-a-blank-flask-page-whenever-i-send-a-post-request-and-try-a-get-request

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...