Pass to and use a variable inside a FlaskForm (WTForms)
问题 The code is pretty self-explanatory - I want to pass a variable to a FlaskForm subclass for further use. from flask import Flask, render_template_string from flask_wtf import FlaskForm from wtforms import StringField from flask_wtf.csrf import CSRFProtect app = Flask(__name__) spam = 'bar' app.secret_key = 'secret' csrf = CSRFProtect(app) @app.route('/') def index(): eggs = spam form = FooForm(eggs) return render_template_string( ''' {{ form.bar_field.label }} {{ form.bar_field }} ''',form =