当前位置 : 主页 > 编程语言 > python >

97 - Flask中如何在Jinjia2模块中使用Python列表

来源:互联网 收集:自由互联 发布时间:2022-07-13
如何在Jinjia2模板中使用复杂数据,如Python列表 ''' Jinjia2 ''' from flask import * app = Flask ( __name__ ) class MyClass : def func ( self ): return 'myclass func' def myfunc (): return 'function' @ app . route ( '/' ) def i


如何在Jinjia2模板中使用复杂数据,如Python列表

'''
Jinjia2

'''

from flask import *

app = Flask(__name__)

class MyClass:
def func(self):
return 'myclass func'

def myfunc():
return 'function'

@app.route('/')
def index():
mydict = {}
mydict['type'] = 'dict'
mylist = []
mylist.append('list')
myclass = MyClass()

return render_template('template.txt', mydict=mydict, mylist=myclass, myclass=myclass, myfunc=myfunc)
if __name__ == '__main__':
app.run() * Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off


* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

98 - 在Jinjia2模板中如何进行条件控制


上一篇:89 - Python一行代码实现循环移位
下一篇:没有了
网友评论