A simple trick to add additional bytes prepending Flask’s stream_with_context
from flask_admin.contrib.sqla import ModelView from itertools import chain class MyAdminView(ModelView): can_export = True column_export_list = ['field1', 'field2'] def _export_csv(self, return_url): r = super(MyAdminView, self)._export_csv(return_url) r.response = chain((b'\xef\xbb\xbf',), r.response) return r
I am still using Python2 and Flask-admin shit. It’s a shame but anyway.
This article is reprinted from: https://blog.est.im/2022/stdout-05
This site is for inclusion only, and the copyright belongs to the original author.