python - How to drill down from entity list to entity instance in Google Appengine? -
i have list of entities, , want use entity key link more details of individual entity.
class routedetails(ndb.model): """get list of routes datastore """ routename = ndb.stringproperty() @classmethod def query_routes(cls): return cls.query().order(-cls.routename) class routespage(webapp2.requesthandler): def get(self): adminlink = authenticate.get_adminlink() authmessage = authenticate.get_authmessage() self.output_routes(authmessage,adminlink) def output_routes(self,authmessage,adminlink): self.response.headers['content-type'] = 'text/html' html = templates.base html = html.replace('#title#', templates.routes_title) html = html.replace('#authmessage#', authmessage) html = html.replace('#adminlink#', adminlink) html = html.replace('#content#', '') self.response.out.write(html + '<ul>') list_name = self.request.get('list_name') #version_key = ndb.key("list of routes", list_name or "*notitle*") routes = routedetails.query_routes().fetch(20) route in routes: routelink = '<a href="route_instance?key={}">{}</a>'.format( route.key, route.routename) self.response.out.write('<li>' + routelink + '</li>') self.response.out.write('</ul>' + templates.footer)
the error getting attributeerror: 'routedetails' object has no attribute 'key'
.
how reference unique id of entity in drilldown url?
the routedetails
object indeed has not key
attribute, exception @ route.key
.
to entity's key need invoke key
attribute/property: route.key
.
but passing entity's key directly through html not work since it's object. urlsafe()
method available provide string representation of key object ok use in html.
so along these lines instead:
route in routes: routelink = '<a href="route_instance?key={}">{}</a>'.format( route.key.urlsafe(), route.routename) self.response.out.write('<li>' + routelink + '</li>')
Comments
Post a Comment