1.加在操作頁面
https://www.quora.com/search?q=flask+view+add+button
% extends 'admin/model/list.html' %}
{% block head %}<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
{% endblock %}
{% block body %}
{{ super() }}
//Add your button
{% endblock %}
2.加在欄位上
https://stackoverflow.com/questions/54378961/flask-admin-how-to-add-button-beside-rows
# Override displayed fields
column_list = ('name', 'value', 'button')
def _format_button(view, context, model, name):
action = url_for('.button_view')
text = "啟用" if model.unable else "關閉"
_html = '''
<form action="{action}" method="POST">
<input id="_id" name="p_id" type="hidden" value="{_id}">
<button type='submit'>{text}</button>
</form>
'''.format(action=action, _id=model.id, text=text)
return Markup(_html)
column_formatters = {
'button': _format_button,
}
@expose('created', methods=['POST'])
def button_view(self):
return_url = self.get_url('.index_view')
form = get_form_data()