[英]different templates are not rendering in flask python
我是 web 开发的新手,我被困在一个过程中,我需要在“POST”和“GET”期间用不同的值(在代码中显示的数据中)呈现相同的模板。
在我的终端中,get 和 post 都是由 python 中的打印语句调用的。
大部分代码取自Record voice with recorder.js 并将其上传到 python-flask 服务器,但 WAV 文件已损坏
@app.route("/", methods=['GET'])
def index_GET():
print('data in get',data)
print('GET IS INVOKED')
return render_template("index.html",q = "hello world",data = 8)
@app.route("/", methods=['POST'])
def index_POST():
f = request.files['audio_data']
basepath = os.path.dirname(__file__)
x = str(datetime.datetime.now()).replace(" ", "").replace(":","").replace(".","")+'.wav'
#upload to database folder uploads
with open(basepath+'/uploads/'+x, 'wb') as audio:
f.save(audio)
print("POST IS INVOKED")
print(data)
print('-'.center(100,'-'))
return render_template("index.html",q = "hello world",data = 1000)
让相同的路由处理这两种方法,然后使用if
语句来做正确的事情:
@app.route("/", methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# Do some processing
return render_template('index.html', data = 'some value')
elif request.method == 'GET':
return render_template('index.html', data = 'some other value')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.