from flask import Flask, url_for from objects import glob # Global sharing of python objects in a manageable way glob.app = Flask(__name__) import routes # All flask app routes if glob.config["disable-static-cache"]: import os @glob.app.context_processor def override_url_for(): """ Generate a new token on every request to prevent the browser from caching static files. """ return dict(url_for=dated_url_for) def dated_url_for(endpoint, **values): if endpoint == 'static': filename = values.get('filename', None) if filename: file_path = os.path.join(glob.app.root_path, endpoint, filename) values['q'] = int(os.stat(file_path).st_mtime) return url_for(endpoint, **values) if __name__ == "__main__": glob.app.run(**glob.config["web"])