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()

相关文章

ipython和python区别详解

ipython和python区别详解

ipython介绍 IPython 是一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell命令,内...

python定时检查启动某个exe程序适合检测exe是否挂了

详见代码如下: 复制代码 代码如下: import threading import time import os import subprocess def get_process_c...

Python文件和流(实例讲解)

1.文件写入 #打开文件,路径不对会报错 f = open(r"C:\Users\jm\Desktop\pyfile.txt","w") f.write("Hello,world!\...

Python rstrip()方法实例详解

Python 字符串 描述 Python rstrip() 删除 string 字符串末尾的指定字符(默认为空格). 语法 rstrip()方法语法: str.rstrip([chars...

python的slice notation的特殊用法详解

python的slice notation的特殊用法详解

如下所示: python的slice notation的特殊用法。 a = [0,1,2,3,4,5,6,7,8,9] b = a[i:j] 表示复制a[i]到a[j-1],以生成新的...