diff --git a/2026-04-28/2026-04-28_hw_1.py b/2026-04-28/2026-04-28_hw_1.py new file mode 100644 index 0000000..adf931c --- /dev/null +++ b/2026-04-28/2026-04-28_hw_1.py @@ -0,0 +1,32 @@ +from flask import Flask, render_template +from flask import flash, redirect, session, request, url_for + +app = Flask(__name__) +app.secret_key = 'Your_secret_key&^52@!' # 设置secret_key + + +@app.route('/home') +@app.route('/') +def home_page(): + username = session.get('username') + # 判断session是否存储username的数据 + if 'username' in session: + return render_template('hw_t1_home_page.html', username=username) + return redirect(url_for('login')) # 重定向到login页面 + + +@app.route('/login', methods=['GET', 'POST']) +def login(): + if request.method == 'POST': + if request.form['username'] != 'admin' or \ + request.form['password'] != '123': + flash('用户名或密码错误', category='error') + else: + session['username'] = request.form['username'] + session['password'] = request.form['password'] + flash('恭喜您,登录成功', category='info') + return redirect(url_for('home_page')) + return render_template('hw_t1_login.html') + +if __name__ == '__main__': + app.run(port=80) \ No newline at end of file diff --git a/2026-04-28/2026-04-28_hw_2.py b/2026-04-28/2026-04-28_hw_2.py new file mode 100644 index 0000000..560474e --- /dev/null +++ b/2026-04-28/2026-04-28_hw_2.py @@ -0,0 +1,13 @@ +from flask import * + +app = Flask(__name__) + + +@app.route('/') +@app.route('/static-file') +def load_staticfile(): + return render_template('hw_t2.html') + + +if __name__ == "__main__": + app.run(port=80) diff --git a/2026-04-28/24计应1_杨近澜_1113_2026-04-28作业.docx b/2026-04-28/24计应1_杨近澜_1113_2026-04-28作业.docx new file mode 100644 index 0000000..00f956c Binary files /dev/null and b/2026-04-28/24计应1_杨近澜_1113_2026-04-28作业.docx differ diff --git a/2026-04-28/static/flask.png b/2026-04-28/static/flask.png new file mode 100644 index 0000000..0d53424 Binary files /dev/null and b/2026-04-28/static/flask.png differ diff --git a/2026-04-28/templates/hw_t1_home_page.html b/2026-04-28/templates/hw_t1_home_page.html new file mode 100644 index 0000000..be14670 --- /dev/null +++ b/2026-04-28/templates/hw_t1_home_page.html @@ -0,0 +1,15 @@ + + +
+ +欢迎用户:{{ username }}
+ + + \ No newline at end of file diff --git a/2026-04-28/templates/hw_t1_login.html b/2026-04-28/templates/hw_t1_login.html new file mode 100644 index 0000000..950fa4c --- /dev/null +++ b/2026-04-28/templates/hw_t1_login.html @@ -0,0 +1,21 @@ + + + + +{{ message }}
+ {% endfor %} + + + + \ No newline at end of file diff --git a/2026-04-28/templates/hw_t2.html b/2026-04-28/templates/hw_t2.html new file mode 100644 index 0000000..c0b1a6c --- /dev/null +++ b/2026-04-28/templates/hw_t2.html @@ -0,0 +1,180 @@ + + + + +Flask-Logo图片
+
+