How can I avoid Flask-Admin 2.1 warning “UserWarning: Fields missing from ruleset”?

可紊 提交于 2019-12-04 21:56:44

问题


I'm using Flask-Admin 2.1 with Python 2.7.6.

One of my Flask-Admin model classes inherits from flask.ext.admin.contrib.sqla.ModelView and overrides form_rules.

When I run my application, this warning is displayed: "UserWarning: Fields missing from ruleset"

The warning is accurate: There are fields in my model that are not included in the ruleset. But that's by design. I don't want those fields to be displayed when users create or edit instances of this model.

I have already read this: https://github.com/flask-admin/flask-admin/pull/815#issuecomment-81963865

How can I suppress the warning?


回答1:


You can suppress the warning when the view is added by using this snippet with the assumed name UserView:

import warnings

with warnings.catch_warnings():
    warnings.filterwarnings('ignore', 'Fields missing from ruleset', UserWarning)
    admin.add_view(UserView())

Reference: https://docs.python.org/2/library/warnings.html#warnings.filterwarnings



来源:https://stackoverflow.com/questions/34091818/how-can-i-avoid-flask-admin-2-1-warning-userwarning-fields-missing-from-rulese

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!