【问题标题】:How to store dynamic form value into datastore using Google App Engine如何使用 Google App Engine 将动态表单值存储到数据存储区
【发布时间】:2023-03-31 15:01:01
【问题描述】:

我正在 html 模板中创建一个动态表单来获取用户选择的货币对。表单如下所示:

用户可以动态添加和删除货币。我使用 Jquery 为第 n 个货币生成了 currency_n 的不同货币对名称。

我最好的问题是如何将它们存储到数据存储中。

如果用户只创建一个货币对(即表单不是动态的),get.request 应该是

    def post(self):
        user_currency_1_1 = self.request.get('currency_1_1')
        user_currency_1_2 = self.request.get('currency_1_2')

我不知道客户提交了多少个货币对,如何获得正确的值?另外,如何设计数据存储结构来存储这些动态内容?

class currency(db.Model):
    user = db.EmailProperty(required = True)
    currency = db.StringProperty(required = True)

【问题讨论】:

    标签: python google-app-engine webapp2


    【解决方案1】:

    我什至不愿回答,因为您没有回答上一个问题的答案。我们不是来为您编写代码的。但是,你很幸运 SO 用户很慷慨。

    跟进我的上一个回答:

    from google.appengine.ext import ndb
    
    class UserCurrencies(ndb.Model):
        user_email = ndb.StringProperty()
        currencies = ndb.JsonProperty(indexed=False)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-21
      • 1970-01-01
      • 1970-01-01
      • 2011-02-16
      • 2013-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多