Pass variable to Python Flask form
<p>I'm currently stuck trying to build a variable message flashing function for my Flask forms</p>

<p>Since I'm building a tool that has to have multiple languages available, I wish to create custom messages for my flask form validation based on specific language input.</p>

<p>My form looks something like this:</p>

<pre><code>class messageForm(FlaskForm):
    title = StringField(
        'title',
        validators=[
            validators.DataRequired(validationMessage('validateRequired', language=language))
        ]
    )
</code></pre>

<p>the function "validationMessage" looks like this:</p>

<pre><code>def validationMessage(message, language):
    msg = Message.query.filter_by(title=message).first()
    lang = Language.query.filter_by(abbr=language).first()
    text = messageBody.query.filter_by(message_id=msg.id, language_id=lang.id).first().text
    return text
</code></pre>

<p>As you notice, I do some lookup in a few database tables to produce my message text. </p>

<p>My trouble is now...
How do I pass my language variable from my view to my form so that I can pass it on to the "validationMessage" function?</p>

<p>The language variable is based on a variable in my view endpoint</p>

<pre><code># Messages
@admin.route('/&lt;string:language&gt;/message', methods=['GET'])
def messageView(language='dk')
    form=messageForm()
    ...
</code></pre>

<p>I have considered using my session for this, but as I understand it, I can only use this within my view and therefore not within either my form or the message function</p>