python - Respons yang dikembalikan oleh bahasa Cina yang tenang menjadi unicode literal
我想大声告诉你
我想大声告诉你 2017-05-18 10:57:32
0
1
848

Kod sampel di bawah dijalankan dalam persekitaran Python 2.7

pip install flask-restful flask
# -*- coding:utf-8 -*-
from flask import Flask
from flask_restful import Api, Resource, reqparse, marshal_with, fields

class Greetings(Resource):
    def get(self, message=None):
        message = '中文한국어'
        greeting = 'You have received a message: {0}'.format(message) if message else 'zzzzzzz......'
        return greeting, 200

app = Flask(__name__)

api = Api(app)

api.add_resource(Greetings, '/radio/', '/radio/<message>')


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

Inilah hasil larian:

            
我想大声告诉你
我想大声告诉你

membalas semua(1)
为情所困

Nyatakan RESTFUL_JSON item konfigurasi:

app = Flask(__name__)
app.config.update(RESTFUL_JSON=dict(ensure_ascii=False))
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan