我需要对从WTForm获得的字符串进行一些操作,这是我的代码:
from app import app
from app.forms import InputTextForm, OutputTextForm
from flask import render_template, request
import re
def work_txt(text):
textlookfor = '[0-9]+\n\d+:\d+:\d+,\d+ --> \d+:\d+:\d+,\d+'
result = re.sub(textlookfor, '', text)
return result
@app.route('/elmucon', methods=['GET', 'POST'])
def elmucon():
form = InputTextForm()
if form.validate_on_submit():
t = request.form.to_dict()
text = t['text']
result = work_txt(text)
return render_template('elmucon_ready.html', form=form, text=result)
function work_txt()在路由之外工作正常,但是使用我的代码,我收到了在Form中输入的相同字符串。我为完成这项工作做了什么?谢谢!