一個需求就是在flask-admin的表格中放入一個根據組id外鍵生成的連接,點擊後跳轉到組flask
from flask_admin.model.template import EndpointLinkRowAction, LinkRowAction #重載類,增長row.group_id這個外鍵id class glink(LinkRowAction): def render(self, context, row_id, row): m = self._resolve_symbol(context, 'row_actions.link') if isinstance(self.url, string_types): row_group_id = row.group_id url = self.url.format(row_id=row_id, row_group_id=row_group_id) else: url = self.url(self, row_id, row) return m(self, url) column_extra_row_actions = [ #注意圖標生成在原有的編輯和刪除的小圖標後面,先根據外鏈的id拼出url glink('glyphicon glyphicon-user', '/admin/group/edit/?url=%2Fadmin%2Fgroup%2F&id={row_group_id}'), EndpointLinkRowAction('glyphicon glyphicon-test', 'user.index_view') ]
以上代碼寫在class UserModelView(ModelView): 中url