我使用flask创建了一个Web应用程序,在main.py中,我有这个
@app.route('/id_cap', methods=["GET", "POST"])
def id_cap():
if request.method == 'POST':
x = request.form["folio"]
print(x)
return redirect(url_for('page_red'))
return render_template("id_cap.html")
@app.route('/video_feed')
def video_feed():
encodes = pd.read_sql_table("Encodes", con=db.engine)
return Response(gen(encodes), mimetype='multipart/x-mixed-replace; boundary=frame')
#edit
@app.route('/enrollment', methods=["GET", "POST"])
def page_red():
with open(target, "rb") as f:
unpickler = pickle.Unpickler(f)
name = unpickler.load()
if name == "noname":
if request.method == 'POST':
params = {"nombre": request.form.get('textbox'), "folio": request.form.get('textbox2')}
encodes = pd.read_sql_table("Encodes", con=db.engine)
id_num = len(encodes)
encode_subj = functionist()#this make the encodes whit face_recognition library
encode_pd = encode_creation(encode_subj, id_num, params)
row_to_write = list(encode_pd.loc[0])
row_value_markers = ','.join(['?']*len(row_to_write))
db.engine.execute("INSERT INTO Encodes VALUES (%s)"%row_value_markers, row_to_write)
return redirect(url_for('index'))
return render_template("enrollment.html")
if name != "noname":
return redirect(url_for('index'))
return render_template("enrollment.html")
在另一个文件中,我有另一个代码
def gen():
doing some stuff with opencv to show camera....
url = 'http://0.0.0.0:5000/id_cap'
myobj = {'folio': folio}
x = requests.post(url, data = myobj)
(flag, encodedImage) = cv2.imencode(".jpg", frame)
yield(b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + bytearray(encodedImage) + b'\r\n')
在执行main.app的控制台中,当我转到/ id_cap页面时,页面无法重定向:
127.0.0.1 - - [02/Jun/2020 15:31:42] "GET /id_cap HTTP/1.1" 200 -
127.0.0.1 - - [02/Jun/2020 15:31:45] "GET /video_feed HTTP/1.1" 200 -
54254354
127.0.0.1 - - [02/Jun/2020 15:31:48] "POST /id_cap HTTP/1.1" 302 -
127.0.0.1 - - [02/Jun/2020 15:31:48] "GET /enrollment HTTP/1.1" 302 -
127.0.0.1 - - [02/Jun/2020 15:31:48] "GET / HTTP/1.1" 200 -
这里的整数行是id_cap()上打印的x,因此该帖子会被应用接收,但不会重定向,欢迎在这里提出任何建议或帮助