Python Flask – How to dynamically handle image and folder generation

Solution
Flask(static_folder=..., static_url_path=...)
Flask(static_url_path="/home/maxloo/pyrest/static")
Flask(static_folder="/home/maxloo/pyrest/static")
@app.router("/static/")   # /
def static(path):
    return send_from_directory(static_folder, path)  # (static_dir, path)
from flask import Flask

template_dir = "/home/maxloo/pyrest"
static_dir   = "/home/maxloo/pyrest/static"

app = Flask(__name__, template_folder=template_dir, static_folder=static_dir)#, static_url_path='/static')

@app.route("/petri/")
def getPetriFile(uuid):
    petri_folder = f'{static_dir}/temp/workdir/{uuid}/petri/'
    
    if not os.path.exists(petri_folder):
        Path(petri_folder).mkdir(parents=True, exist_ok=True)
        # copy some file to folder
        shutil.copy(f'{static_dir}/LATEST.png', f'{petri_folder}/LATEST.png')
        
    # it has to start with `/static`
    image_url = f"/static/temp/workdir/{uuid}/petri/LATEST.png"
    
    return render_template("image.html", user_image=image_url)