У меня есть форма, использующая WTForm, и я хотел бы показать, что пользователь ввел. Например, допустим, пользователь ввел «Рыбу». Он пройдет через мой файл python и проверит, если пользователь введет «Рыбу», откройте эту картинку рыбы в файле result.html после отправки формы. Конечно, этот пример использования Fish просто для вашего понимания, моя программа не имеет ничего общего с рыбами.
/main.py
def destination():
dest = DestinationForm(request.form)
error = None
if request.method == "POST":
if dest.validate():
with shelve.open('transportStorage') as transportStorage:
transportStorage['journeyName'] = dest.journeyName.data
transportStorage['busNumber'] = int(dest.busNumber.data)
transportStorage['busstopCode'] = int(dest.busstopCode.data)
transportStorage['destination'] = dest.destination.data
transportStorage['busID'] = dest.busID.data
transportStorage['alertMe'] = int(dest.alertMe.data)
for d in listofBuses:
for key, value in d.items():
if key == dest.busNumber.data:
dictData = value
for busstopCode, place in dictData.items():
if dest.busstopCode.data == busstopCode:
dest.busstopCode.data = place
return render_template("results.html",dest=dest, dictData=dictData)
else:
error = "Sorry, bus number is not in record!"
return render_template("destinationForm.html",dest=dest, error=error)
else:
return render_template("destinationForm.html", dest=dest, error=error)
else:
return render_template("destinationForm.html", dest=dest, error=error)
else:
return render_template("destinationForm.html", dest=dest, error=error)
/ForWtform.py
class DestinationForm(Form):
journeyName = StringField("Name this Journey", validators=[DataRequired(),
Length(min=2, max=20, message="Journey Name must be between 2 and 20" characters long.")])
busNumber = IntegerField("Select Bus Number", validators=[DataRequired()])
busstopCode = IntegerField("Bus Stop Code", validators=[DataRequired(message="Invalid Bus Code!")])
destination = StringField("Destination", validators=[DataRequired(), Length(min=2, max=20, message="Invalid Destination!")])
busID = StringField("Bus ID", validators=[DataRequired(), Length(min=5, max=8, message="Invalid Bus ID!")])
alertMe = SelectField("Alert me before: ", choices=[('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5')],
validators=[DataRequired()])
submit = SubmitField("Submit")
/results.html
What to do i place here to show the image ?