Python Flask, how to set content type

前端 未结 7 1605
走了就别回头了
走了就别回头了 2020-12-02 05:10

I am using Flask and I return an XML file from a get request. How do I set the content type to xml ?

e.g.

@app.route(\'/ajax_ddl\')
def ajax_ddl():
          


        
7条回答
  •  甜味超标
    2020-12-02 06:11

    from flask import Flask, render_template, make_response
    app = Flask(__name__)
    
    @app.route('/user/xml')
    def user_xml():
        resp = make_response(render_template('xml/user.html', username='Ryan'))
        resp.headers['Content-type'] = 'text/xml; charset=utf-8'
        return resp
    

提交回复
热议问题