经过上一篇的学习,网站有了基本的框架结构。可是只返回这种字符串如何能行,基本的HTML文件还是需要的。
果然,下一个例子通过一个叫render_template方法,调用了HTML文件。
from flask import Flask, render_template
# ...
@app.route('/index')
def index():
return render_template('index.html')
@app.route('/user/<name>')
def user(name):
return render_template('user.html', name=name)
嗯,看起来只需要修改对应的2个方法,把之前返回字符串改为使用render_template,把HTML和需要用到的参数传递给他就OK。
不过HTML文件是放在哪里呢?
checkout对应的版本后,发现是在一个叫templates的文件夹下。(这