值已存储在 geo = ndb.GeoPtProperty 中 我想在 django 模板上打印它 但 obj print 不是值
即使我尝试打印 attr
geo.lat # try this also
geo.latitude # try this also
即使是全名也不起作用
不确定你的意思
obj print not value
。
以下代码有效
class Geo(ndb.Model):
created = ndb.DateTimeProperty(auto_now_add=True)
location = ndb.GeoPtProperty()
@classmethod
def create_record(cls, latitude, longitude):
return cls(location = ndb.GeoPt(latitude, longitude)).put()
@classmethod
def get_records(cls):
return cls.query().fetch()
@app.route("/test_geo/")
def create_geo():
key = Geo.create_record(52.37, 4.88)
logger.info(f"key: {key}")
output = Geo.get_records()
for a in output:
logger.info (f"lat:{a.location.lat}, long: {a.location.lon}")
# The above line gives
lat:52.37, long: 4.88
return "done"