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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>