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)