其他操作按钮在flask

编程入门 行业动态 更新时间:2024-10-28 02:21:22
本文介绍了其他操作按钮在flask-admin上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I'm trying to add one more action to flask-admin forms.

它必须增加等级(+1),并且可以批量操作,但不能单次操作.请帮助我找到该错误,我花了很多时间尝试使此问题正常运行.

It has to increment rating (+1) and it works with batch action, but not with single. Please help me find the bug, I've spent a lot of time trying to make this thing work properly.

代码如下:

我在模板文件夹-custom_lists.html

I made an html template in templates folder - 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 %}

此操作成功,并在列表上显示一个图标,但是如果我单击它,它会显示

this succeeded with an icon on the list, but if i click to it - it says

未找到

在服务器上找不到请求的URL.如果输入URL 手动,请检查您的拼写,然后重试.

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

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

added to templates folder and added to AdidasView class this:

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.sessionmit() 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函数,做了如下不同的操作

I have not changed the template but I have done it differently as following by setting the column_extra_row_actions variable and defining the action_play function

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()

更多推荐

其他操作按钮在flask

本文发布于:2023-07-20 17:40:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1169636.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   操作   flask

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!