V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
carlosw
V2EX  ›  Python

flask-wtf SelectFiled 相关问题

  •  
  •   carlosw · 2019-11-25 23:48:52 +08:00 · 2436 次点击
    这是一个创建于 1584 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我创建了一个 flask-wtf 的表单,有一项是 selection 类型,choices 选项我想使用一个变量,但是不知道需要怎么传进去。有人知道嘛?

    class Connection(FlaskForm):
        env = SelectField(
            label = '环境选择:  ',
            render_kw={ 'class': 'form-control' },
            choices = [('default', 'default'), ('dev', 'dev'), ('hotfix', 'hotfix')], # 这里查资料都是要写死,不知道怎么使用变量
            default = 'default',
            coerce=str
        )
    
    4 条回复    2019-11-26 21:00:19 +08:00
    lbfeng
        1
    lbfeng  
       2019-11-26 00:06:16 +08:00
    def __init__(self, **kwargs):
    super(Connection, self).__init__(**kwargs)
    self.env.choices = [ ]
    self.env.default =
    coolair
        2
    coolair  
       2019-11-26 07:55:10 +08:00 via Android
    到 view 里面去设置
    carlosw
        4
    carlosw  
    OP
       2019-11-26 21:00:19 +08:00
    @altboy 解决了 ,十分感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5503 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 09:03 · PVG 17:03 · LAX 02:03 · JFK 05:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.