web.py中调用文件夹内模板的方法

yipeiwu_com7年前Python基础

web.py的模板使用非常容易,但有时候我们需要做目录层级以便管理。那么如何使用目录层级的模板呢?

通常我们使用模板的时候先声明模板文件夹

复制代码 代码如下:

render=web.template.render('templates')

使用templates文件夹下index.html模板
复制代码 代码如下:

return render.index()

使用templates文件夹下list.html模板
复制代码 代码如下:

return render.list()

以上所有的html模板文件只放在tempates目录下,如果要在templates下建目录并使用目录下的模板文件只需加目录名称即可。
使用templates下的admin目录里的index.html模板
复制代码 代码如下:

return render.admin.index()

使用templates下的admin目录里的login.html模板
复制代码 代码如下:

return render.admin.login()

相关文章

Python实现读写INI配置文件的方法示例

本文实例讲述了Python实现读写INI配置文件的方法。分享给大家供大家参考,具体如下: # -*- coding: utf-8 -*- import ConfigParser im...

解决nohup重定向python输出到文件不成功的问题

原因是: It looks like you need to flush stdout periodically (e.g. sys.stdout.flush()). In my t...

Python3实现统计单词表中每个字母出现频率的方法示例

本文实例讲述了Python3实现统计单词表中每个字母出现频率的方法。分享给大家供大家参考,具体如下: 作为python字典与数组概念的运用,统计字母表中每个字母出现的频率,作为练习再合适...

解决Python3用PIL的ImageFont输出中文乱码的问题

解决Python3用PIL的ImageFont输出中文乱码的问题

今天在用python3+ImageFont输出中文时,结果显示乱码 # coding:utf-8 from PIL import Image, ImageDraw, ImageFon...

python多线程http压力测试脚本

本文实例为大家分享了python多线程http压力测试的具体代码,供大家参考,具体内容如下 #coding=utf-8 import sys import time import...