From 811c5afcc09f1080466f204b4e1b83a6018733d9 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Thu, 8 Sep 2022 21:59:27 +0800 Subject: Serve from /xlsx --- __main__.py | 26 +++++++++++++++++++++----- templates/index.html | 6 +++--- 2 files changed, 24 insertions(+), 8 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/") +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: diff --git a/templates/index.html b/templates/index.html index c5edd1f..ad48dc1 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,7 +2,7 @@ 高中风险地区表格压缩器 -

高中风险地区表格压缩器

@@ -15,7 +15,7 @@ {% endif %} {% endwith %} -
+ 点击查看使用说明

表格格式

- +

图中高亮部分是压缩器会读取的数据,其他部分将会被忽略,但是黄色部分不能删除。 -- cgit v1.2.3