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.
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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With