docs: 2026-04-14作业
This commit is contained in:
32
2026-04-14/2026-04-14_hw_1.py
Normal file
32
2026-04-14/2026-04-14_hw_1.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from flask import Flask, after_this_request
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.before_first_request
|
||||
def before_first_request():
|
||||
print('这是请求钩子 before_first_request 注册的函数')
|
||||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
print('这是请求钩子 before_request 注册的函数')
|
||||
|
||||
@app.route('/index')
|
||||
def index():
|
||||
print('hello flask')
|
||||
@after_this_request
|
||||
def after_this_request_func(response):
|
||||
print('这是请求钩子 after_this_request_func 注册的函数')
|
||||
return response
|
||||
return 'hello flask'
|
||||
|
||||
@app.after_request
|
||||
def after_request(response):
|
||||
print('这是请求钩子 after_request 注册的函数')
|
||||
return response
|
||||
|
||||
@app.teardown_request
|
||||
def teardown_request(error):
|
||||
print('这是请求钩子 teardown_request 注册的函数')
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
26
2026-04-14/2026-04-14_hw_2.py
Normal file
26
2026-04-14/2026-04-14_hw_2.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from flask import Flask, url_for, request, redirect, session
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = 'Your_secret_key$^52@!'
|
||||
|
||||
@app.route('/index')
|
||||
def index():
|
||||
if 'username' in session:
|
||||
return f'你好,{session.get("username")}'
|
||||
return redirect(url_for("login"))
|
||||
|
||||
@app.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
if request.method == 'POST':
|
||||
session['username'] = request.form['username']
|
||||
return redirect(url_for('index'))
|
||||
# 当发送GET请求时,页面显示输入框和"登录"按钮
|
||||
return '''
|
||||
<form method="post">
|
||||
<p><input type=text name=username>
|
||||
<p><input type=submit value=登录>
|
||||
</form>
|
||||
'''
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
BIN
2026-04-14/2026-04-14_hw_3.docx
Normal file
BIN
2026-04-14/2026-04-14_hw_3.docx
Normal file
Binary file not shown.
BIN
2026-04-14/24计应1_杨近澜_1113_2026-04-14作业.docx
Normal file
BIN
2026-04-14/24计应1_杨近澜_1113_2026-04-14作业.docx
Normal file
Binary file not shown.
Reference in New Issue
Block a user