我是烧瓶和python的新手,我想定制瓶皮 restAPI,以返回(纬度、经度),而不是JSON中的MerchantDetail.Address。我需要对API对象进行更多的更改,而不是直接从mysql表中获取值。
from flask_peewee.rest import RestAPI
from geopy import geocoders
from app import app # our project's Flask app
from models import MerchantDetail
# instantiate our api wrapper
api = RestAPI(app)
# register our models so they are exposed via /api/<model>/
api.register(MerchantDetail)
# g = geocoders.GoogleV3()
# place, (lat, lng) = g.geocode(MerchantDetails.Address)
# configure the urls
api.setup()发布于 2013-10-01 16:28:53
如果我理解您的问题,您希望更改您的API输出,以便MerchantDetail包含其他属性(place、lat、lng),这些属性目前不在模型中。有两种方法可以做到这一点:
1.)将这些字段添加到模型中,并将其挂钩到应用程序中,以便在创建新的MerchanDetail时,运行地理代码并与模型一起存储结果。
2.)使用RestResource (参见关于“自定义返回的内容”的文档)。REST资源可以覆盖prepare_data()方法来运行地理编码,并将结果存储在传出数据中。
https://stackoverflow.com/questions/19105543
复制相似问题