From 515e17b1b885a16720436b8c2b76ec82b9400d20 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 12 May 2024 15:56:42 +0800 Subject: [PATCH] =?UTF-8?q?flask=E8=BE=93=E5=85=A5=E5=A4=87=E6=B3=A8?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=BB=BA=E8=AE=BE=E4=B8=AD,=20=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=9B=BE=E7=89=87=E9=97=AE=E9=A2=98=E5=B7=B2=E8=A7=A3?= =?UTF-8?q?=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 工具v4/flask框架.py | 14 ++++++++++++++ 工具v4/templates/index.html | 26 +++++--------------------- 工具v4/templates/show_image.html | 23 +++++++++++++++++++++++ 工具v4/templates/show_remarks.html | 11 +++++++++++ 工具v4/备注信息收集.py | 26 ++++++++++++++++---------- 6 files changed, 70 insertions(+), 31 deletions(-) create mode 100644 工具v4/templates/show_image.html create mode 100644 工具v4/templates/show_remarks.html diff --git a/.gitignore b/.gitignore index 6e8a356b..1c882ef7 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ *使用指南*.html **/*test* *.sh +*static diff --git a/工具v4/flask框架.py b/工具v4/flask框架.py index 05036216..349f4069 100644 --- a/工具v4/flask框架.py +++ b/工具v4/flask框架.py @@ -10,5 +10,19 @@ def index(): return render_template('result.html', checkboxes=selected_checkboxes, radioboxes=selected_radioboxes) return render_template('index.html') +@app.route('/testhello') +def hello(): + return "Hello World" + + +@app.route('/blog/') +def blog_detail(blog_id): + return f"您访问的博客是: {blog_id}" + +@app.route('/book/list') +def book_list(): + page = request.args.get("page", default=1, type=int) + return f"您获取的是第{page}页图书列表" + if __name__ == '__main__': app.run(debug=True) \ No newline at end of file diff --git a/工具v4/templates/index.html b/工具v4/templates/index.html index 84cee40c..98dfe2df 100644 --- a/工具v4/templates/index.html +++ b/工具v4/templates/index.html @@ -1,29 +1,13 @@ - Flask App - + 登记备注 -

Hello World

-
-
-
- Checkbox 1
- Checkbox 2
- Checkbox 3
-
-
- Radiobox 1
- Radiobox 2
- Radiobox 3
- Radiobox 4
-
-
+

登记备注

+ + +
diff --git a/工具v4/templates/show_image.html b/工具v4/templates/show_image.html new file mode 100644 index 00000000..782952f3 --- /dev/null +++ b/工具v4/templates/show_image.html @@ -0,0 +1,23 @@ + + + + 输入备注 + + +

输入备注

+
+ +

+ +

+ +
+

题目内容

+ Question Image + + \ No newline at end of file diff --git a/工具v4/templates/show_remarks.html b/工具v4/templates/show_remarks.html new file mode 100644 index 00000000..fa052fb4 --- /dev/null +++ b/工具v4/templates/show_remarks.html @@ -0,0 +1,11 @@ + + + + 显示备注 + + +

显示备注

+

备注类型: {{ category }}

+

备注内容: {{ remarks }}

+ + \ No newline at end of file diff --git a/工具v4/备注信息收集.py b/工具v4/备注信息收集.py index eb275265..b97ef48f 100644 --- a/工具v4/备注信息收集.py +++ b/工具v4/备注信息收集.py @@ -1,19 +1,25 @@ -from flask import Flask, render_template, request -from database_tools_2 import * +from flask import Flask, render_template, request, redirect, url_for +import os app = Flask(__name__) -@app.route('/', methods=['GET', 'POST']) +@app.route('/') def index(): + return render_template('index.html') + +@app.route('/show_image', methods=['POST']) +def show_image(): if request.method == 'POST': - text1 = request.form['text1'] - text2 = request.form['text2'] - category = request.form['category'] - AppendTextFile(f"{text1.zfill(6)}\n({GetDate()}{category}){RefinePunctuations(text2)}\n","临时文件/备注收集.txt") + global question_number + question_number = request.form['question_number'] - return "备注收集完成, 感谢支持数据库建设" - - return render_template('remarkindex.html') + return render_template('show_image.html', image_path=f'/static/{question_number}.png') + +@app.route('/submit_remarks', methods=['POST']) +def submit_remarks(): + category = request.form['category'] + remarks = request.form['remarks'] + return render_template('show_remarks.html', category=category, remarks=remarks) if __name__ == '__main__': app.run(debug=True) \ No newline at end of file