I am trying to call a regular function into RadioField - choices[()]. when i select a radio button on my web page and click submit button, i should get the result from from function. my function says to print("Hi"). currently it print's the data on given value like 'value_one' when i select description.
So, i need a way to do call function to choices[('')]. below is my code
from flask import Flask, render_template
from flask_wtf import Form
from wtforms import RadioField, SubmitField
app = Flask(__name__)
app.config.from_object(__name__)
app.secret_key = 'password'
def print_1():
print("Hi")
class SimpleForm(Form):
example = RadioField('Label', choices=[('value_one','description'),('value_two','whatever')])
@app.route('/',methods=['post','get'])
def hello_world():
form = SimpleForm()
if form.validate_on_submit():
print(form.example.data)
else:
print(form.errors)
return render_template('form.html',form=form)
if __name__ == '__main__':
app.run(debug=True)
Below is my html code:
<form method="post">
{{ form.hidden_tag() }}
{{ form.example }}
<input type="submit" value="submit">
</form>