search

Home  >  Q&A  >  body text

python - Flask 如何不用渲染模板直接输出 html 文件

(我是想,在构建一个网站,全异步加载。即,用户先载入静态 html 文件,然后利用 jQuery 从服务端通过与 App 相同的 API 载入数据。)

Flask 如何直接输出静态 HTML 文件而不经过渲染?

高洛峰高洛峰2804 days ago1310

reply all(4)I'll reply

  • 阿神

    阿神2017-04-17 13:13:22

    Cheek Nao

    @app.route('/')
    def root():
        return app.send_static_file('index.html')
    

    Reference stackoverflow
    Reference official documentation

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 13:13:22

    Flask directly creates the output Restful API.
    The front-end jQuery can directly request data to render the page.
    The front end can also use some js frameworks, such as angular.js and ember.js, etc.

    reply
    0
  • 黄舟

    黄舟2017-04-17 13:13:22

    You can put the rendering template on the front end

    13 JavaScript template engines

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:13:22

    This first loads the static html. In the html, you can use jQuery to call the written REST API to load the data, and then parse the data on the browser side and present it.

    reply
    0
  • Cancelreply