如何在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模板中如何进行条件控制