【发布时间】:2019-02-01 20:51:00
【问题描述】:
我正在尝试向烧瓶管理表单添加一项操作。
它必须增加评分 (+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 %}
这成功了,列表上有一个图标,但是如果我点击它-它会说
找不到
在服务器上找不到请求的 URL。如果您输入了 URL 请手动检查您的拼写,然后重试。
添加到模板文件夹并添加到 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')
【问题讨论】:
标签: python flask jinja2 flask-sqlalchemy flask-admin