我有一個 API,它在導航到每個網址http://www.example.com/list時返回一個 JSON 列表。示例 JSON 列表如下:{ "name": "This is a name"}但我也想用另一種語言提供這個確切的 JSON 列表,例如法語:{ "name": "C'est un nom"}我設法做的是有 2 個不同的網址:1 為英語: http: //www.example.com/en/list。1 法語: http: //www.example.com/fr/list。然后在我的代碼中我有兩個類,1 個用于英語,1 個用于法語:class ItemList_En(Resource):def get(self): return {"name": "This is a name"}class ItemList_Fr(Resource):def get(self): return {"name": "C'est un nom"}api.add_resource(ItemList_En, "/en/list")api.add_resource(ItemList_Fr, "/fr/list")我想知道這是否是唯一的方法?有沒有更好的方法我不知道,因為我是 Python 和 Flask 的新手。如果有人能幫助我,我將不勝感激。
添加回答
舉報
0/150
提交
取消