首先请原谅我在 django、python 和 html 方面的笨拙。
我在 html 中添加了小部件,我想从数据库中填充项目。我尝试了以下但它不起作用,它只显示明显的('ALL' 项目):
HTML:
<select name=\"accountName\" >
<option value=\"ALL\">ALL</option>
{% for item in select_items %}
<option value=\"'+item.accountName+'\">'+item.accountName+'</option>
{% endfor %}
</select>
python :
class StartPage(webapp.RequestHandler):
def get(self):
select_items = db.GqlQuery( "SELECT * FROM Registration" )
self.response.out.write(template.render("tst.html", {'select_items': select_items}))
请注意,数据库确实包含内容,而不是空的。 谢谢
请您参考如下方法:
我不是 django 专家,但我认为你的模板有一些错误。
<option value=\"'+item.accountName+'\">'+item.accountName+'</option>
应该是
<option value="{{ item.accountName }}">{{ item.accountName }}</option>
更多信息: https://docs.djangoproject.com/en/dev/topics/templates/
