python中的GET请求不起作用
我有这个python代码。每当我启动Web服务器并访问该网站时,我不会得到消息测试,只是内部服务器错误。怎么会?我做错了什么。无论何时我去网站,它都是一个正确的GET请求,所以它应该进入域函数并给我文本测试python中的GET请求不起作用,python,function,post,get,flask,Python,Function,Post,Get,Flask,我有这个python代码。每当我启动Web服务器并访问该网站时,我不会得到消息测试,只是内部服务器错误。怎么会?我做错了什么。无论何时我去网站,它都是一个正确的GET请求,所以它应该进入域函数并给我文本测试 @app.route("/", methods=['GET', 'POST']) def hello(): if request.method == 'GET': domain() else: test() def domain():
@app.route("/", methods=['GET', 'POST'])
def hello():
if request.method == 'GET':
domain()
else:
test()
def domain():
return "test"
def test():
data = request.get_json()
with open("text.txt", "w") as text_file:
pickle.dump(data, text_file)
if __name__ == "__main__":
app.run()
因为你没有返回任何可以在网页上显示的内容。返回测试只是返回字符串,而该字符串无处可去 你需要像这样的东西:
if request.method == 'GET':
return render_template('page.html', domain=domain())
确保代码正在导入:
hello函数不返回域test的返回值。测试功能相同:
@app.route("/", methods=['GET', 'POST'])
def hello():
if request.method == 'GET':
return domain()
else:
return test()
谢谢,成功了!,我输入了一些我认为不需要展示的东西,但返回是个问题。我会尽快接受你的回答!谢谢
@app.route("/", methods=['GET', 'POST'])
def hello():
if request.method == 'GET':
return domain()
else:
return test()