Answers for "how to fix flask cache issue in python"

1

how to fix flask cache issue in python

# fix flask cache issue
from flask import *

import os

# default root : http://127.0.0.1:5000/

app = Flask(__name__)

#----------------------------------------------------
##   FIRST METHOD

##   You can simply set this to 0
# app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0

# @app.route("/", methods=["POST", "GET"])
# def home():
#     return render_template("index.html")
#---------------------------------------------------
#---------------------------------------------------
#	SECOND METHOD
#   This gets the last version of the cache
#   I've tried this method and it works
def dir_last_updated(folder):
    return str(max(os.path.getmtime(os.path.join(root_path, f))
                   for root_path, dirs, files in os.walk(folder)
                   for f in files))

@app.route("/", methods=["POST", "GET"])
def home():
#   Get the current path of the program
    path = os.getcwd()
    path = path.replace('\\', '/')
#   Now you set last_updated to the last cache
    return render_template("index.html", last_updated=dir_last_updated(path+"/static"))


if __name__ == "__main__":
    app.run(debug=True)
Posted by: Guest on November-12-2020

Code answers related to "how to fix flask cache issue in python"

Python Answers by Framework

Browse Popular Code Answers by Language