【问题标题】:Serve an external full webpage trough Flask通过 Flask 提供外部完整网页
【发布时间】:2015-01-04 16:16:21
【问题描述】:

我正在尝试执行以下操作:

文件结构如下:

/app
    /static
        /start
            /css
            /js
            - index.html
    /templates

我想知道如何在不使用 url_for('static', filename='') 或其他类型的服务槽 Flask 的情况下提供此 index.html 并使其加载其 CSS 和 JS。

基本上,我想把@987654321@ 和槽 Flask serve index.html 像<link href="css/style.css" rel="stylesheet">一样加载自己的css和js

我尝试了send_from_directory('/static/start', "index.html")app.send_static_file('index.html'),但它们不起作用。

我也尝试过current_app.send_static_file('start/index.html'),但这仅适用于 html。它不会让 index.html 加载自己的 CSS 和 JS。

我从这些链接中获得了信息

  • How to serve static files in Flask
  • python flask - serving static files
  • Flask: How to serve static html?
  • 他们没有做我想做的事(或者我做错了)。

    提前致谢,如果需要更多信息,请告诉我。

    【问题讨论】:

      标签: python html static web


      【解决方案1】:

      您可以将常规 html 文件加载为 jinja 模板。直接调用render,不带任何参数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-17
        • 1970-01-01
        • 1970-01-01
        • 2014-04-12
        • 1970-01-01
        • 2018-08-05
        相关资源
        最近更新 更多