I have this in the Google App Engine python code,
class ABC(db.Model):
StringA = db.StringProperty()
abcs = ABC.all()
template_values = {'abcs': abcs,}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
and this in the index.html,
<script type="text/javasc开发者_StackOverflow社区ript">
{% for abc in abcs %}
var id = "{{ abc.ID }}"; // needed the entity ID, the abc.ID doesn't show??
{% endfor %}
</script>
What was the right keyword to use for the entity ID, the abc.ID??
Thanks in advance.
{{abc.key.id}}
, assuming you're using Django templates. The ID isn't a property of the object, it's a part of the object's Key; in a Django template (which is what you're using if you're using google.appengine.ext.webapp.template), this is the equivalent to abc.key().id()
in Python code.
Note that not all entities have an ID at all; they could have a key name instead if you've set one.
精彩评论