【问题标题】:Assiging a value to wtform field为 wtforms 字段赋值
【发布时间】:2014-08-27 13:25:19
【问题描述】:

我有一个如下所示的列表

 self.glb_data_list = [{'disp_type': '2'}]

我想将此“disp_type”值分配给 wtform 下拉字段“disp_type”。这是我的 wtforms 字段

    disp_type = fields.SelectField(u'Preset Mapping',
                                      choices=[(0, u'Custom'),
                                      (1, u'Loopback'),
                                      (2, u'All_East'),
                                      (3, u'All_Wast'),
                                      (4, u'16_East_16_West'),
                                      (5, u'8_East_8_West'),
                                      (6, u'STM1_East')],
                                    coerce=int, default=0) 

有人可以指导我如何分配

【问题讨论】:

  • 如果coerceintglb_data_list 应该是[{'dist_type': 2}](整数值)
  • 为什么 glb_data_list 是一个字典列表而不是一个字典?

标签: python python-2.7 wtforms wt


【解决方案1】:
self.glb_data_list = {'disp_type': 2}

disp_type = fields.SelectField(u'Preset Mapping',
                                      choices=[(0, u'Custom'),
                                      (1, u'Loopback'),
                                      (2, u'All_East'),
                                      (3, u'All_Wast'),
                                      (4, u'16_East_16_West'),
                                      (5, u'8_East_8_West'),
                                      (6, u'STM1_East')],
                                    coerce=int, default=0) 

disp_type.data = self.glb_data_list['dist_type']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多