from flask import Flask, render_template, request, redirect, url_for import os,shutil from database_tools_2 import * app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') @app.route('/show_image', methods=['POST']) def show_image(): if request.method == 'POST': id = request.form['question_number'].zfill(6) mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = "tiku") mycursor = mydb.cursor() sql = "SELECT content FROM problems WHERE ID = %s;" val = (id,) mycursor.execute(sql,val) content = mycursor.fetchall()[0][0] mydb.close() latex_raw = ReadTextFile("模板文件/独立文件模板.txt") latexdata = StringSubstitute(r"<<待替换\d*>>",latex_raw,[content]) makedir("临时文件/pics") currentdate = GetDate() currenttime = GetTime() SaveTextFile(latexdata,f"临时文件/pics/ID{id}-{currentdate}-{currenttime}.tex") os.system(f"xelatex -interaction=batchmode -output-directory=临时文件/pics ID{id}-{currentdate}-{currenttime}.tex") os.chdir("临时文件/pics") os.system(f"pdftocairo -png -r 600 ID{id}-{currentdate}-{currenttime}.pdf") os.chdir("../..") shutil.copy(f"临时文件/pics/ID{id}-{currentdate}-{currenttime}-1.png",f"static/{id}.png") return render_template('show_image.html', image_path=f'/static/{id}.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)