from flask import Flask, request, make_response, render_template
import settings
app = Flask(__name__)
app.config.from_object(settings)
@app.route(‘/index‘)
def index():
print(request.headers)
print(request.path)
print(request.url)
return ‘welcome everyone‘
@app.route(‘/register‘)
def register():
r = render_template(‘register.html‘)
print(r)
return r
@app.route(‘/register2‘)
def register2():
#return ‘进来了‘
print(request.full_path)
print(request.path)
print(request.args)
print(request.args.get(‘username‘))
print(request.args.get(‘address‘))
###如果通过POST方式的话,在route 中 传递参数 method=[‘POST‘]
###通过request.form.get(‘username‘) request.form.get(‘adddress‘)
if __name__ == ‘__main__‘:
app.run(port=8000,debug=True)
#############
在templates 文件夹下新增html文件,命名为register,与路由名称相同
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>欢迎来到京东购物网站</title>
</head>
<h1>欢迎哈</h1>
<url>
<li>Hello abc</li>
<li>Hi 123</li>
<li>World</li>>
</url>
<!--如果是表单提交,必须加name属性-->
<form action="register2" method="get">
<p><input type="text" name=‘username‘ placeholder="请输入用户名"></p>
<p><input type="text" name=‘address‘ placeholder="请输入地址"></p>
<p><input type="submit" value="提交"></p>
</form>>
<body>
</body>
</html>
template 与视图关联