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")
原文地址:https://www.cnblogs.com/codeblock/p/flask-tiao-zhuan-jing-taihtml.html