Flask-admin-如何更改列的格式-获取要显示的URL [英] Flask-admin - how to change formatting of columns - get URLs to display
问题描述
关于flask-admin的问题.我设置了flask-admin,创建的模型之一是从mysql数据库中提取URL和URL标题.使用flask-admin,如何让flask-admin呈现URL,而不仅仅是文本?因此,使用户只需单击flask-admin应用程序中的链接即可更轻松地进行操作.谢谢.
Question on flask-admin. I setup flask-admin and one of the models i created is pulling urls and url titles from a mysql database. Using flask-admin, how to i get flask-admin to render the urls instead of just text? So make it easier for users to just click on the link from the flask-admin app. Thank you.
我在flask-admin网站上找到了称为列格式化程序的内容,但不确定如何实现.有没有人可以分享的榜样?谢谢.
I found something on the flask-admin site called column formatters, but not sure how to implement. Does anyone have an example they can share? Thanks.
推荐答案
假设您有一个名为MyView的视图,并且您的模型具有url字段,则下面的urltitle将起作用.
Assuming you have a view named MyView, and your model has fields url, and urltitle then below would work.
from flask import Markup
class MyView(ModelView)
def _user_formatter(view, context, model, name):
if model.url:
markupstring = "<a href='%s'>%s</a>" % (model.url, model.urltitle)
return Markup(markupstring)
else:
return ""
column_formatters = {
'url': _user_formatter
}
这篇关于Flask-admin-如何更改列的格式-获取要显示的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!