我看到了answer(第二个),建议在 request
中添加一个字段(例如device = "web")来决定从REST API返回到web或Android应用程序的 response
.
建议方式:
@app.route('/test', methods=['GET'])
def test():
device = request.args.get('device')
if device is "web":
return render_template('test.html', data='Hello Word')
else:
# Return data to Android Application
return json.dumps({'data':'Hello World'})
我发现它非常有用,但是,作者自己说这是一种粗暴的方式,而且还有更好的方法 .
请建议我一个更好的方法,谢谢 .
1 回答
我不熟悉Flask,但从一般的,语言/平台无关的角度来看,IMO最好的方法可能是以前端不可知的方式构建REST API . 然后,您的网络应用程序,移动应用程序以及未来的任何其他内容都以相同的方式使用它 .