summaryrefslogtreecommitdiff
path: root/__main__.py
diff options
context:
space:
mode:
Diffstat (limited to '__main__.py')
-rw-r--r--__main__.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/__main__.py b/__main__.py
index 1902718..de9540c 100644
--- a/__main__.py
+++ b/__main__.py
@@ -1,4 +1,13 @@
-from flask import Flask, render_template, request, redirect, flash, send_file, after_this_request
+from flask import (
+ Flask,
+ render_template,
+ request,
+ redirect,
+ flash,
+ send_file,
+ after_this_request,
+ send_from_directory,
+)
import os
import logging
import secrets
@@ -7,22 +16,29 @@ from pathlib import Path
from .compress import compress
UPLOAD_FOLDER = Path(gettempdir()) / "risksheet"
+URL_PATH = "/xlsx" # https://example.com/xlsx
app = Flask(__name__)
app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
# NOTE: the secret key will be regenerated each time this application is run
# this is ok because we don't store credentials in the cookie
app.secret_key = secrets.token_hex()
+app.static_url_path = "xlsx/static"
-logging.basicConfig(filename=UPLOAD_FOLDER / "risksheet.log")
+logging.basicConfig(filename=UPLOAD_FOLDER / "risksheet.log", level=logging.WARNING)
-@app.get("/")
+@app.get(URL_PATH + "/static/<path:name>")
+def subpath_static(name):
+ return send_from_directory("static", name)
+
+
+@app.get(URL_PATH)
def index():
- return render_template("index.html")
+ return render_template("index.html", path=URL_PATH)
-@app.post("/")
+@app.post(URL_PATH)
def sheet():
# receive and validate file
try: