
Web
|
335
<title>Flask3 Example</title>
</head>
<body>
Say hello to my little friend: {{ thing }}.
Alas, it just destroyed {{ place }}!
</body>
</html>
有很多方法可以将第二个参数传给
echo
URL
。
通过
URL
路径传递参数
使用该方法,只需扩展
URL
本身即可。将例
18-10
中的代码保存为
flask3a.py
。
例
18-10
flask3a.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/echo/<thing>/<place>')
def echo(thing, place):
return render_template('flask3.html', thing=thing, place=place)
app.run(port=9999, debug=True)
和往常一样,停止先前的测试服务器脚本(如果正在运行的话),然后尝试下面这个新
脚本:
$
python flask3a.py
输入下列
URL
:
http://localhost:9999/echo/Rodan/McKeesport
应该会看到如下内容:
Say hello to my little friend: Rodan. Alas, it just destroyed McKeesport! ...