gpt4 book ai didi

python - 附加操作按钮在 flask-admin 上不起作用

转载 作者:行者123 更新时间:2023-11-28 20:58:05 37 4
gpt4 key购买 nike

我正在尝试向 flask-admin 表单添加一项操作。

enter image description here

它必须增加评级 (+1) 并且它适用于批处理操作,但不适用于单个操作。请帮我找到错误,我花了很多时间试图让这个东西正常工作。

代码如下:

我在模板文件夹中制作了一个 html 模板 - custom_lists.html

{% extends 'admin/model/list.html' %}
{% block list_row_actions %}
{{ super() }}
<form class="icon" method="POST" action="/admin/user/action/">
<input id="action" name="action" value="approve" type="hidden">
<input name="rowid" value="{{ get_pk_value(row) }}" type="hidden">
<button onclick="return confirm('Are you sure you want to approve selected items?');" title="Approve">
<span class="fa fa-ok glyphicon glyphicon-ok"></span>
</button>
</form>
{% endblock %}

这成功了,列表中有一个图标,但如果我点击它 - 它说

Not Found

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

添加到模板文件夹并添加到 AdidasView 类:

list_template = 'custom_list.html'
@action('approve', 'Approve', 'Are you sure you want to approve selected items?')
def action_approve(self, ids):
try:
query = Adidas.query.filter(Adidas.id.in_(ids))

count = 0
for image in query.all():
image.rating += 1
count += 1
db.session.commit()
flash(ngettext('Item was successfully approved.',
'%s items were successfully approved.'%count,count))
except Exception as ex:
if not self.handle_view_exception(ex):
raise

flash(gettext('Failed to approve items. %(error)s', error=str(ex)), 'error')

最佳答案

我没有更改模板,但我通过设置 column_extra_row_actions 变量和定义 action_play 函数做了不同的操作

column_extra_row_actions = [
EndpointLinkRowAction('glyphicon glyphicon-play', 'event.action_play')
]

@expose('/action/play', methods=('GET',))
def action_play(self, *args, **kwargs):
return self.handle_action()

关于python - 附加操作按钮在 flask-admin 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52037226/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com