flask-admin部署到linux报错 too many values to unpack (expected 2)

发布于 2022-09-06 10:05:54 字数 2050 浏览 38 评论 0

我把我的项目上传到linux环境后,解压之后,配置数据库及其app为
host=‘0.0.0.0’,port=5005
之后运行起来了,可是点击到自定义的model 就是各种报错,报错内容都是一样的;可是在我的个人window环境却完全没有问题,这是环境哪里有问题吗?

File "/root/app/esayblog/apps/templates/admin/lib.html", line 190, in template
    {{ render_field(form, f, kwargs) }}
  File "/root/.pyenv/versions/3.6.1/lib/python3.6/site-packages/jinja2/runtime.py", line 579, in _invoke
    rv = self._func(*arguments)
  File "/root/app/esayblog/apps/templates/admin/lib.html", line 121, in template
    {% if field(**kwargs) is not none %}{% set testlabel = field(**kwargs) %}
  File "/root/.pyenv/versions/3.6.1/lib/python3.6/site-packages/wtforms/fields/core.py", line 153, in __call__
    return self.meta.render_field(self, kwargs)
  File "/root/.pyenv/versions/3.6.1/lib/python3.6/site-packages/wtforms/meta.py", line 56, in render_field
    return field.widget(field, **render_kw)
  File "/root/.pyenv/versions/3.6.1/lib/python3.6/site-packages/flask_admin/form/widgets.py", line 28, in __call__
    return super(Select2Widget, self).__call__(field, **kwargs)
  File "/root/.pyenv/versions/3.6.1/lib/python3.6/site-packages/wtforms/widgets/core.py", line 287, in __call__
    for val, label, selected in field.iter_choices():
  File "/root/.pyenv/versions/3.6.1/lib/python3.6/site-packages/flask_admin/contrib/sqla/fields.py", line 168, in iter_choices
    for pk, obj in self._get_object_list():
  File "/root/.pyenv/versions/3.6.1/lib/python3.6/site-packages/flask_admin/contrib/sqla/fields.py", line 102, in _get_object_list
    self._object_list = [(text_type(get_pk(obj)), obj) for obj in query]
  File "/root/.pyenv/versions/3.6.1/lib/python3.6/site-packages/flask_admin/contrib/sqla/fields.py", line 102, in <listcomp>
    self._object_list = [(text_type(get_pk(obj)), obj) for obj in query]
  File "/root/.pyenv/versions/3.6.1/lib/python3.6/site-packages/flask_admin/contrib/sqla/fields.py", line 299, in get_pk_from_identity
    cls, key = identity_key(instance=obj)
ValueError: too many values to unpack (expected 2)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落叶缤纷 2022-09-13 10:05:54

终于解决了!
原来的是同一个flask_sqlalchemy版本,但是linux版本和window版本的下的orm/mapper.py的一个方法返回的元组个数不一样;window版返回两个是正确的;linux版本返回三个,存在bugger,估计现在是刚更新的和flask_admin还没有同步:
window版的源码:

  def identity_key_from_primary_key(self, primary_key):
        """Return an identity-map key for use in storing/retrieving an
        item from an identity map.

        :param primary_key: A list of values indicating the identifier.

        """
        return self._identity_class, tuple(primary_key)

linux版本的:

def identity_key_from_primary_key(self, primary_key, identity_token=None):
        """Return an identity-map key for use in storing/retrieving an
        item from an identity map.

        :param primary_key: A list of values indicating the identifier.

        """
        return self._identity_class, tuple(primary_key), identity_token

所以把源码给改成一样的就可以了;
或者把他的调用方法给改了:

flask_admin/contrib/sqla/fields.py 改成:
def get_pk_from_identity(obj):
    # TODO: Remove me
    print(obj.__dict__)
    print(obj.__dict__['id'])
    #cls, key = identity_key(instance=obj)
    key = identity_key(instance=obj)[1]
    return u':'.join(text_type(x) for x in key)
即可,终于发现python的好处就该源码容易!!
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文