国产成人AV无码一二三区,少女1到100集,国产精品久久久久精品综合紧,巜公妇之诱感肉欲HD在线播放

文章 > Flask > flask中模板引擎怎么用?

flask中模板引擎怎么用?

头像

小妮浅浅

2021-02-21 11:13:298185浏览 · 0收藏 · 0评论

在我们对flask的一些引擎使用时,就不得不提到其中的一个默认引擎了。有些初学flask的人对Jinja2还没有使用过,所以不知道该从何下手。本篇对于这种默认的引擎使用进行了整理,有对flask模板引擎感兴趣的,可以跟着我们一起来看看Jinja2的基础操作,具体的内容如下展开。

1、flask默认的模板引擎是Jinja2

目录结构:

/application.py
/templates
    /oscuser.html

2、实例

application.py
#coding=utf-8
__author__ = 'duanpeng'
 
 
import MySQLdb
from  flask import  Flask,request,render_template,session, redirect, url_for, escape
app = Flask(__name__,static_folder='static',static_url_path='/static')
 
 
#定义首页
@app.route('/')
def hello_world():
     user_agent = request.headers.get('User-Agent')
     return 'welcom! ,you browser is %s' % user_agent
 
 
#定义404错误页面
@app.errorhandler(404)
def not_found(error):
    return render_template('error.html'), 404
 
 
 
#定义动态页面
@app.route('/user/<username>')
def show_user_profile(username):
    # show the user profile for that user
    return 'User %s' % username
 
#限制请求方式
@app.route('/sayHello',methods=['post'])
def sayHello():
     return "hello,who are you?"
#限制请求只能为get方式
@app.route('/touch',methods=['get'])
def touch():
     return render_template('bank.html')
 
 
#我的账号页面,与数据库交互,实现动态数据处理
@app.route('/myaccount',methods=['get'])
def mydata():
    try:
        #加载驱动 连接数据库    host ->ip port->端口
        conn = MySQLdb.connect(host='192.168.1.124',user='root',passwd='abcdef',db='abcdef',port=3306,charset='gb2312')
        cursor = conn.cursor()
        cursor.execute("select * from osc_users t where t.login_name = 'rainbow07693'")
        result  = cursor.fetchone()
        print(result[4])
        cursor.close()
        conn.close()
        return render_template('oscuser.html',userinfo=result)
    except MySQLdb.Error,e:
        print e
 
 
 
if __name__ == '__main__':
app.run(debug=True)

以上就是flask中模板引擎的使用,相信大家已经对Jinja2的用法有了一定的认识。平时在课后也可以找有关的资料进行深入学习。更多Python框架指路:Flask

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

《朋友的未婚妻》| 《家庭教师》漫画免费阅读下拉式| 《再来一次好吗》免费观看| 老师好爽要尿了潮喷了18P| 《黏糊糊的你》动漫免费观看| 1秒流鼻血的女性胸片| 一母四女共一婿的全诗解读| 《课后2对1特别授课》女主角是..| 白日梦我 电视剧| 涂了春药的奶头被众人抡H漫画 | 婆媳双飞杨钰莹阅读| 老公说我越来越骚的心理| 免费B站看大片真人电视剧| 50岁阿姨大人免费观看电视剧| 扒开腿让我躁你很舒服的导演是谁| 《灭火宝贝2》美国版| 《特殊的家政服务》| 日本CSGO大姐姐AWP| 周翊然| 护士小嫩嫩好紧好爽H漫画| D124| 女生给男生吃小头头| 真人版结婚之夜女性教育PPT| WWW.77.GOVCN| 按摩师精油按摩下面会得妇科病吗| 蜜桃成熟时2| 性生交大片免费观看A片| 美国禁忌4结局免费| B站暴躁姐的丈夫是干什么的| 继母后妈的梗| 女人脱精光让人桶爽了| 国产旗袍裙人妻人伦| 年轻嫂子| 爸井空《办公室爱欲》| 成都私人情侣免费看电视剧的软件 | 《再来一次好吗》免费观看| 每日大赛 反差吃瓜爆料合集视频| 老师穿黑色双开真丝旗袍如何穿芭..| 《疯狂伴娘》在线观看| 女性左腿又开腿肚子视频大全| C2000论坛