我目前正在努力编写一些Python Flask代码。我有一个现有的xml文件,其中包含一些值,每当在某个URL上完成GET请求时,我都希望发送这些值。
我似乎无法将已经存在的XML发送回发送get请求的客户机。有谁能帮帮我吗?
from app import app
from flask import request, Response, render_template, make_response
@app.route('/')
def index():
return "Hello World, this is the index page"
@app.route('/inventory')
def inventory():
if(request.method == "GET"):
#Here should the return happen of the existing xml-file我的XML-file与这段代码不在同一个目录中。如果这段代码在"localhost/app/routes.py“中,那么xml文件就在"localhost/resources/resources.xml”中。
我尝试了不同的方法,但似乎都不起作用(flask的响应、render_template、make_response等)。
有什么想法吗?
发布于 2018-10-29 13:28:15
我想我发现了一些东西:
通过使用Flask导入objectify,我可以将XML文件作为对象读取,然后对其进行调整。完成后,我可以简单地将其转换回XML格式的字符串。
https://stackoverflow.com/questions/53024567
复制相似问题