Python 使用restful flask呈现HTML网页-网页未正确显示

Python 使用restful flask呈现HTML网页-网页未正确显示,python,html,flask-restful,Python,Html,Flask Restful,我正在尝试使用restful flask api在本地主机上呈现HTML页面。HTML页面的内容显示为带“”的字符串,而不是页面 class data(Resource): def get(self): #return "Welcome!" return render_template('index.html') api.add_resource(data,'/') My index.html文件包含以下内容 <!DOCTYPE html>

我正在尝试使用restful flask api在本地主机上呈现HTML页面。HTML页面的内容显示为带“”的字符串,而不是页面

class data(Resource):
    def get(self):
        #return "Welcome!"
        return render_template('index.html')


api.add_resource(data,'/')
My index.html文件包含以下内容

<!DOCTYPE html>
<html>
<body>
<h1>Welcome to the site!</h1>
</body>
</html>
"<!DOCTYPE html>\n<html>\n<body>\n<h1>Welcome to the Data Hosting Service</h1>\n</body>\n</html>"

您可能需要从
flask
导入
make_repsone
以呈现包含标题信息的html

from flask import make_response, render_template
headers = {'Content-Type': 'text/html'}
return make_response(render_template('index.html'),200,headers)

希望这会有帮助。

这可能是因为您继承了
资源。RESTful API通常返回未呈现HTML内容的JSON字符串。您能告诉响应的内容类型吗。可能是Restful将默认值从text/html更改为text或json。我应该如何解决这个问题?类型是unicode
from flask import make_response, render_template
headers = {'Content-Type': 'text/html'}
return make_response(render_template('index.html'),200,headers)