Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Flask Admin自定义列表视图_Flask_Flask Admin - Fatal编程技术网

使用Flask Admin自定义列表视图

使用Flask Admin自定义列表视图,flask,flask-admin,Flask,Flask Admin,我有一个简单的模型调用,我使用Flask Admin创建/编辑/删除这个模型的实例 调用字段之一是音频文件的路径。我想能够通过添加一些html代码在管理中播放该文件。我检查了模板flask\u admin/templates/bootstrap3/admin/model/list.html,似乎我想要做的唯一方法是在行的末尾添加一个单元格,这意味着扩展list.html,复制整个块list\u行,然后添加我的单元格 这是唯一的办法吗?或者有没有办法用我的音频播放器(基本上是html5)在表单中添

我有一个简单的模型调用,我使用Flask Admin创建/编辑/删除这个模型的实例

调用字段之一是音频文件的路径。我想能够通过添加一些html代码在管理中播放该文件。我检查了模板
flask\u admin/templates/bootstrap3/admin/model/list.html
,似乎我想要做的唯一方法是在行的末尾添加一个单元格,这意味着扩展list.html,复制整个块
list\u行
,然后添加我的单元格

这是唯一的办法吗?或者有没有办法用我的音频播放器(基本上是html5)在表单中添加一个“假”字段

flask_admin/templates/bootstrap3/admin/model/list.html


有一种更简单的方法,可以使用:

在模板中:

class CallView(sqla.ModelView):
    column_formatters = dict(path=macro('render_path_mp3'))
{% macro render_path_mp3(model, column) %}
   <a href="{{ url_for('path_to_mp3_view', filename=model.path) }}">{{ model.name }}</a>
{% endmacro %}
{%macro render\u path\u mp3(模型,列)%}
{%endmacro%}

创建自定义视图函数
路径\u到\u mp3\u视图
作为练习被省略了……)

这是一个旧线程,但为了将来的参考,现在有
列\u额外的\u行\u操作
BaseListRowAction
。更多信息请点击此处:

太好了,谢谢。不过,我将使用
audio
html5标记。
from flask import Markup

class CallView(sqla.ModelView):
    def _mp3_formatter(view, context, model, name):
        return Markup('<a href="{}">{}</a>'.format(url_for('path_to_mp3_view', filename=model.path), model.name)
    column_formatters = {
       'path': _mp3_formatter
    }
class CallView(sqla.ModelView):
    column_formatters = dict(path=macro('render_path_mp3'))
{% macro render_path_mp3(model, column) %}
   <a href="{{ url_for('path_to_mp3_view', filename=model.path) }}">{{ model.name }}</a>
{% endmacro %}