I have a Flask (It's not actually Flask, it's Quart, an asynchronous version of Flask with the same syntax and features) application that serves static files that are created temporarily by a command line tool. I want to delete the files after they have been served. I can do this with a normal route (not static) like so (pseudo-code, not tested):
@after_this_request
def delete_file():
path = "C:\Windows\System32\explorer.exe"
os.remove(path)
My question is, how do I achieve the same thing with a static file?
Solved it by creating a blueprint and letting it do all the lifting for static files. I'll make a suggestion to Flask and Quart to add an official version of this feature. If you're using Flask, not Quart, then change all the
async def
s todef
static_bp.py:
main.py (Replace Quart with Flask if you are running Flask):