Skip to main content
 首页 » 编程设计

python之减少 Flask-Admin 中列的大小

2025年05月04日15lyhabc

有没有办法限制 ModelView 列的大小(长度/宽度)?我使用的是 WYSIWYG 编辑器,这会创建非常长的文本,因此使 ModelView 的列非常长。

这是它的外观图片。查看右侧最后一列。它甚至比屏幕截图可以处理的还要长。

请您参考如下方法:

不显示列(通过排除):

class MyView(ModelView): 
 
    column_exclude_list = ('description') 

不显示列(通过包含):

class MyView(ModelView): 
 
    column_list = ('rating', 'category_id', 'year', 'stock', 'image')    

重新格式化列:

class MyView(ModelView): 
 
     def _description_formatter(view, context, model, name): 
        # Format your string here e.g show first 20 characters 
        # can return any valid HTML e.g. a link to another view to show the detail or a popup window 
        return model.description[:20] 
 
    column_formatters = { 
        'description': _description_formatter, 
    }