“在代码的世界里,每一行都是进步的足迹,每一次挑战都是成长的机遇。”

Flask 配置可以访问某个文件的下的静态内容

一种方式:@app.route('/article/<path:filename>')
def get_article(filename):
    """
    这个函数用于处理对/article路径下文件的访问请求,
    会从article目录下查找对应的html文件并返回。
    """
    return send_from_directory('article', filename)
另一种方式:
配置Flaskd的静态static_folder,
app = Flask(__name__, static_folder='static')
以下是源码,不设置默认是static
def __init__(
    self,
    import_name: str,
    static_url_path: t.Optional[str] = None,
    static_folder: t.Optional[t.Union[str, os.PathLike]] = "static",
    static_host: t.Optional[str] = None,
    host_matching: bool = False,
    subdomain_matching: bool = False,
    template_folder: t.Optional[t.Union[str, os.PathLike]] = "templates",
    instance_path: t.Optional[str] = None,
    instance_relative_config: bool = False,
    root_path: t.Optional[str] = None,
):

		

Write your comment Here