from flask import Blueprint, current_app, Response from app.services import BookService bp = Blueprint("book", __name__) @bp.route("/download") def book_download(): book_object = BookService() app = current_app._get_current_object() def generate(): with app.app_context(): yield from book_object.book_download() return Response(generate(), mimetype='text/event-stream')