[英]Flask : Unable to render Unicode Characters in Webpage
I am trying to print devnagari (hindi) on a webpage using flask.我正在尝试使用 Flask 在网页上打印 devnagari(印地语)。 However, on browsing to the webpage, the unicode I am passing is converted to a string.
但是,在浏览网页时,我传递的 unicode 被转换为字符串。 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:如果您使用 Flask 的make_response返回响应实例,则可以正常工作:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.