栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Django前戏

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Django前戏

current_time datetime.datetime.now().strftime( %Y-%m-%d %X ) # 如何将后端获取到的数据 传递 给html文件 with open(r templates/03 mytime.html , r , encoding utf-8 ) as f: data f.read() # data就是一堆字符串 data data.replace( ###$$### ,current_time) # 在后端将html页面处理好之后再返回给前端 return data # 将一个字典传递给html文件 并且可以在文件上方便快捷的操作字典数据 from jinja2 import Template def get_dict(env): user_dic { username : xltx0311 , age :18, hobby : read_book } with open(r templates/get_dict.html , r ,encoding utf-8 ) as f: data f.read() tmp Template(data) res tmp.render(user user_dic) # 给get_dict.html传递了一个值 页面上通过变量名user就能够拿到user_dict return res # 后端获取数据库中数据展示到前端页面 5、模版语法之Jinja2模块
pip3 install jinja2
 模版语法是在后端起作用的 
# 模版语法(非常贴近python语法)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/267538.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号