• flask跳转静态html


    1. 问题描述

    在使用flask开发web的时候啊,并不是所有的页面都需要template进行修饰吧,如果我们用return render_template("xxx/xxx/xxx.html")来进行页面跳转xxx.html,那么xxx.html一定是经过模板引擎(如jinja2)修饰过的,纯静态html应该没什么问题,但是如果这个静态页面使用anjularjs,静态页面代码部分{{}}会jinja2给理解成它自己的东东,这不就造成混乱了!怎么办呢?

    2. 解决办法

    我们可以通过在from flask import send_file
    通过return send_file("xxx/xxx/xxx.html")来返回静态html,这个html不经过jinja2修饰,会达到跟直接浏览器打开一样的效果。
    如下我使用蓝图的时候的代码片段

    from flask import Blueprint,render_template,send_file
    
    
    rally_keystone = Blueprint('rally_keystone',__name__,url_prefix='/rally/keystone')
    
    
    @rally_keystone.route('/')
    @rally_keystone.route('/index')
    def index():
        return render_template('rally/keystone/keystone_index.html')
    
    @rally_keystone.route('/detail')
    def detail():
        return send_file("templates/rally/keystone/test.html")
    
  • 相关阅读:
    SPOJ Distinct Substrings(后缀数组求不同子串个数,好题)
    POJ 1743 Musical Theme(后缀数组+二分答案)
    HDU 6191 Query on A Tree(可持久化Trie+DFS序)
    swust oj 1052
    swust oj 1051
    swust oj 1016
    swust oj 1014
    swust oj 1013
    swust oj 1012
    swust oj 1011
  • 原文地址:https://www.cnblogs.com/codeblock/p/flask-tiao-zhuan-jing-taihtml.html
Copyright © 2020-2023  润新知