Answer the question
In order to leave comments, you need to log in
Is it possible to use multiple SelectField attributes in one object?
I have the simplest Flask application, I found a behavior that is incomprehensible to me, I'm curious what this is connected with, I hope that someone will clarify. The bottom line is this: when adding a test (test = SelectField(u'Test', choices=[('0', '0'), ('1', '1')]))), even an unused SelectField field to an object, the application stops responding properly to pressing the submit button, just refreshes the page, does not write anything either to the console or to the web.
run.py
from flask import Flask, render_template, flash
from flask_wtf import FlaskForm
from flask_wtf.csrf import CSRFProtect
from wtforms import SelectField, SubmitField
app = Flask(__name__)
csrf = CSRFProtect(app)
class Config(object):
SECRET_KEY ='123123123qweasdzxc'
app.config.from_object(Config)
class Exploits(FlaskForm):
test = SelectField(u'Test', choices=[('0', '0'), ('1', '1')])
language = SelectField(u'Programming Language', choices=[('cpp', 'C++'), ('py', 'Python'), ('text', 'Plain Text')])
use = SubmitField('Выбрать')
@app.route("/", methods=['GET', 'POST'])
def home():
form = Exploits()
if form.validate_on_submit():
print('SUBMIT!!!')
flash('Botton is submited {}'.format(form.language.data))
return render_template('index.html', form=form)
if __name__ == "__main__":
app.run(debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
<form action="" method="post" novalidate>
{{ form.csrf_token }}
{{ form.language }}
{{ form.use }}
</form>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question