|
@@ -1,28 +1,26 @@
|
|
|
from flask import Flask
|
|
|
+from flask import request
|
|
|
+from flask import make_response
|
|
|
+from flask import redirect
|
|
|
app=Flask(__name__)
|
|
|
|
|
|
@app.route('/')
|
|
|
def index():
|
|
|
- return '<h1>hello world!</h1>'
|
|
|
+ method=request.method
|
|
|
+ user_agent=request.headers['User_Agent']
|
|
|
+ return '请求方法为%s<br>你的UA为%s' % (method,user_agent)
|
|
|
|
|
|
-@app.route('/hello/<name>')
|
|
|
-def hello(name):
|
|
|
- return '<h1>hello '+name+'!</h1>'
|
|
|
+@app.route('/404')
|
|
|
+def return404():
|
|
|
+ return '404 not found',404
|
|
|
|
|
|
+@app.route('/login')
|
|
|
+def login():
|
|
|
+ response=make_response('登录成功,并记住密码!')
|
|
|
+ response.set_cookie('username','Felix')
|
|
|
+ response.set_cookie('pw_hash','d45...ae17f')
|
|
|
+ return response
|
|
|
|
|
|
-@app.route('/book/<string:name>')
|
|
|
-def book(name):
|
|
|
- return '<h1>I like book 《%s》!</h1>'% name
|
|
|
-
|
|
|
-@app.route('/<int:num1>/plus/<int:num2>')
|
|
|
-def plus(num1,num2):
|
|
|
- return '<h1>%s+%s=%s</h1>'%(num1,num2,num1+num2)
|
|
|
-
|
|
|
-@app.route('/height/<float:num>/m')
|
|
|
-def height(num):
|
|
|
- cm=num*100
|
|
|
- return 'My height is %s cm!' % cm
|
|
|
-
|
|
|
-@app.route('/location/<path:location>')
|
|
|
-def whereami(location):
|
|
|
- return 'Your location is %s .' % location
|
|
|
+@app.route('/baidu')
|
|
|
+def baidu():
|
|
|
+ return redirect('https://www.baidu.com')
|