简体   繁体   中英

Flask : Unable to render Unicode Characters in Webpage

I am trying to print devnagari (hindi) on a webpage using flask. However, on browsing to the webpage, the unicode I am passing is converted to a string. Program -

from flask import jsonify, Flask
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)

class Text(Resource):
    def get(self):
        textInput = u'\u0960'
        return textInput

api.add_resource(Text, '/')

if __name__ == '__main__':
    app.run(debug=True)

Output :

"\u0960"

Expected Output :

If you use Flask's make_response to return a response instance, it works fine:

from flask import jsonify, Flask, make_response
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)

class Text(Resource):
    def get(self):
        textInput = u'\u0960'
        return make_response(textInput)

api.add_resource(Text, '/')

if __name__ == '__main__':
    app.run(debug=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM