程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python series - filter walkthrough

編輯:Python
  • filter
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html',
name=" taiyangxue ",
html='<b>Bob</b>')
@app.route('/filter')
def filter():
return render_template('filter.html', data={
'name': 'Bob',
'age': 23,
'city': 'Beijing'
}, data1=False, name=None,
list=[1,2,3,4])
# Define filter functions
def mylen(arg):# Implement a function that can find the length
return len(arg)
def interval(test_str, start, end): # Returns the contents of a specified interval in a string
return test_str[int(start):int(end)]
# Registration filter
env = app.jinja_env
env.filters['mylen'] = mylen
env.filters['interval'] = interval
# The view function
@app.route('/myfilter')
def myfilter():
return render_template('myfilter.html', phone='13300000000')
# Control structure if-else
@app.route('/hello2/<name>/<gender>')
def hello2(name, gender):
return render_template('hello2.html', name=name, gender=gender)
# Control structure for
@app.route('/names')
def names():
return render_template('for.html', names=['Lily', 'Bob', 'Tom', 'Jan'])
# macro
@app.route('/marco')
def marco():
return render_template('mymarco.html', names=['Lily', 'Bob', 'Tom', 'Jan'])
# Inherit
@app.route('/hello3')
def hello3():
return render_template('hello3.html')
if __name__ == '__main__':
app.run(debug=True) 

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved