【问题标题】:How to store value in html without showing on page如何在html中存储值而不显示在页面上
【发布时间】:2014-02-04 04:16:03
【问题描述】:

我正在使用 Jinja2 和 Google App Engine。

我用整数 num 来识别我的模型:

class TestModel(db.Model):
    value = db.StringProperty()
    num = db.IntegerProperty()

并有一个用于编辑值的类:

class Edit(Handler):
    def get(self):
        #show input box with value, let user edit value, render page with num


    def post(self):
        #get new value, filter database for model instance BY NUM and replace with new value

我需要在页面上存储 num 以便我可以为 post 方法检索它,但我不希望页面显示它。

我试过了:

<span name = "num" value = "{{num}}"></span>

在 post 方法中我有

 num = self.request.get('num')
 logging.error("NUM: %s" % num)

但是当我运行它时,日志中没有显示 num(我有“NUM:”)并且我得到了

ValueError: invalid literal for int() with base 10: ''

当我渲染页面时,源代码显示 num 在那里。为什么这段代码不能正确检索 num?

【问题讨论】:

    标签: html google-app-engine jinja2


    【解决方案1】:

    您是否尝试过将字段放入隐藏的输入元素中。即

    <input type="hidden" name="..." value="..."/>
    

    还要确保您尝试在帖子中检索的值在表单标签内。

    【讨论】:

    • 就是这样,谢谢。为什么输入标签有效而不是跨度标签?
    猜你喜欢
    • 1970-01-01
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    • 1970-01-01
    • 2018-04-07
    • 2021-01-08
    相关资源
    最近更新 更多