tornado 模板
生活随笔
收集整理的這篇文章主要介紹了
tornado 模板
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用模板 render
在 application 中配置模板文件和靜態文件的路徑:
template_path=‘templates’,static_path=‘static’,
templates文件夾存放的是模板
statics文件夾拆分的是資源
示例
<body>歡迎{{ username }}登錄</body> class TemplatesHandler(tornado.web.RequestHandler):def get(self):self.render('02template.html', username='no')def post(self):username = self.get_argument('username', 'no')self.render('02template.html', username=username)模板符號
跟django一樣
用 {{ expression }} 中間是任何 python 表達式,或者是一個變量
{{ 1 + 1 }} {{ time.time() }}{% directives %}
{% if 1 %} this is if{% end %}{% if username != 'no' %}歡迎{{ username }}登錄 { % else %}請登錄 {% end %}模板轉義
通過模板,可以把數據動態的添加到頁面,如果添加的值是一段html代碼的話,會不會被執行呢?
{% raw atga %}
raw 可以自模板中去掉轉義,讓 tornado 在渲染的時候不去轉義變量
模板去轉義
靜態文件的引用
模板繼承
include
{% include filename%}
include 可以導入一些其他的模板文件,一般使用 include 的時候,模板文件中不使用 block 塊
總結
以上是生活随笔為你收集整理的tornado 模板的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 搭建问答系统
- 下一篇: 能用m18-H2丝锥量内螺纹m18x2.