Уведомления

Группа в Telegram: @pythonsu
  • Начало
  • » Web
  • » selectfield заполнение результатом запроса [RSS Feed]

#1 Май 19, 2019 10:26:48

dbalor
Зарегистрирован: 2018-07-02
Сообщения: 73
Репутация: +  0  -
Профиль   Отправить e-mail  

selectfield заполнение результатом запроса

Как во flask заполнить результатом запроса selectfield ?

Делаю так:

 ...
    sql = 'SELECT * FROM dirFilial'
    fres = db.engine.execute(sql)
    names = [(frow[0],frow[1]) for frow in fres]
    filial=SelectField('Филиал',choises=names)
...

Выдает ошибку:
 Traceback (most recent call last):
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/flask/app.py", line 2328, in __call__
    return self.wsgi_app(environ, start_response)
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/flask/app.py", line 2314, in wsgi_app
    response = self.handle_exception(e)
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/flask/app.py", line 1760, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/flask/_compat.py", line 36, in reraise
    raise value
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/flask/app.py", line 2311, in wsgi_app
    response = self.full_dispatch_request()
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/flask/app.py", line 1834, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/flask/app.py", line 1737, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/flask/_compat.py", line 36, in reraise
    raise value
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/flask/app.py", line 1832, in full_dispatch_request
    rv = self.dispatch_request()
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/flask/app.py", line 1818, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/srv/www/htdocs/rac/index.py", line 32, in index
    form=LoginForm()
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/wtforms/form.py", line 212, in __call__
    return type.__call__(cls, *args, **kwargs)
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/flask_wtf/form.py", line 158, in __init__
    super(Form, self).__init__(*args, **kwargs)
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/flask_wtf/form.py", line 88, in __init__
    super(FlaskForm, self).__init__(formdata=formdata, **kwargs)
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/wtforms/form.py", line 272, in __init__
    super(Form, self).__init__(self._unbound_fields, meta=meta_obj, prefix=prefix)
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/wtforms/form.py", line 52, in __init__
    field = meta.bind_field(self, unbound_field, options)
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/wtforms/meta.py", line 27, in bind_field
    return unbound_field.bind(form=form, **options)
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/wtforms/fields/core.py", line 353, in bind
    return self.field_class(*self.args, **kw)
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/wtforms/fields/core.py", line 449, in __init__
    super(SelectField, self).__init__(label, validators, **kwargs)
  File "/srv/www/htdocs/rac/venv/lib/python3.6/site-packages/wtforms/fields/core.py", line 418, in __init__
    super(SelectFieldBase, self).__init__(label, validators, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'choises'

Отредактировано dbalor (Май 19, 2019 10:27:44)

Офлайн

#2 Май 22, 2019 09:22:42

FishHook
От:
Зарегистрирован: 2011-01-08
Сообщения: 8006
Репутация: +  558  -
Профиль   Отправить e-mail  

selectfield заполнение результатом запроса

dbalor
попробуйте перевести choises гугл-переводчиком



Офлайн

#3 Май 22, 2019 13:00:34

dbalor
Зарегистрирован: 2018-07-02
Сообщения: 73
Репутация: +  0  -
Профиль   Отправить e-mail  

selectfield заполнение результатом запроса

Спасибо, решил проблему:

 ...
filial=SelectField('Филиал',coerce=int,choices=[(i.id,i.fname) for i in db.engine.execute(sql)])
...

Офлайн

  • Начало
  • » Web
  • » selectfield заполнение результатом запроса[RSS Feed]

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version