husstanden/main.py

30 lines
824 B
Python
Raw Normal View History

2019-02-12 16:59:43 +01:00
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 and not filename.startswith("const/"):
2019-02-12 16:59:43 +01:00
file_path = os.path.join(glob.app.root_path,
endpoint, filename)
values["q"] = int(os.stat(file_path).st_mtime)
2019-02-12 16:59:43 +01:00
return url_for(endpoint, **values)
if __name__ == "__main__":
glob.app.run(**glob.config["web"])