【发布时间】:2017-08-21 02:00:48
【问题描述】:
在下面的代码中,我想将 URL 存储在变量中以检查发生 URL 错误的错误。
@app.route('/flights', methods=['GET'])
def get_flight():
flight_data= mongo.db.flight_details
info = []
for index in flight_data.find():
info.append({'flight_name': index['flight_name'], 'flight_no': index['flight_no'], 'total_seat': index['total_seat'] })
if request.headers['Accept'] == 'application/xml':
template = render_template('data.xml', info=info)
xml_response = make_response(template)
xml_response.headers['Accept'] = 'application/xml'
logger.info('sucessful got data')
return xml_response
elif request.headers['Accept'] == 'application/json':
logger.info('sucessful got data')
return jsonify(info)
输出:
* Restarting with stat
* Debugger is active!
* Debugger PIN: 165-678-508
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [28/Mar/2017 10:44:53] "GET /flights HTTP/1.1" 200 -
我想要这条消息
"127.0.0.1 - - [28/Mar/2017 10:44:53] "GET /flights HTTP/1.1" 200 -"
应该存储在一个变量中,或者如何获取当前正在执行的 URL?
【问题讨论】:
标签: python python-3.x url flask