如何在html中显示python变量的值(在这种情况下,它是我的Entity类的键)?
from google.appengine.ext import db
class Entity(db.Expando):
pass
e = Entity()
e.put() # id is assigned
k = e.key() # key is complete
id = k.id() # system assigned id
html=”’
Key: %(k)
”’
解决方法:
from google.appengine.ext import db
import cgi
class Entity(db.Expando):
pass
e = Entity()
e.put() # id is assigned
k = e.key() # key is complete
id = k.id() # system assigned id
html=”””
Key: %s
“”” % (cgi.escape(k))
我会认真地建议你使用模板虽然它让你的生活更轻松.
使用模板,您的解决方案将是这样的:
class Entity(db.Expando):
pass
e = Entity()
e.put() # id is assigned
k = e.key() # key is complete
id = k.id() # system assigned id
template = jinja_environment.get_template(‘templates/myTemplate’)
self.response.write(template.render({‘key_val’:k}))
并且Mytemplate.html文件看起来像:
{
{key_val}}
标签:html,python,google-app-engine