How can I use request.form in Flask/Python to get a variable textarea name?
<p>In my HTML template, I've added the following <code>&lt;textarea&gt;</code> into a flask for loop:</p>

<pre><code>{% for message in messageList %}
    &lt;form action="/comment/{{ message['id'] }}" method='POST' id='createComment{{ message["id"] }}'&gt;
        &lt;textarea name='comment{{ message["id"] }}' id='comment{{ message["id"] }}' class='postComment'&gt;&lt;/textarea&gt;
        &lt;button form='createComment{{ message["id"] }}' formaction="/comment/{{ message['id'] }}" formmethod='post' type='submit' class="ui-button ui-corner-all ui-widget createCommentButton"&gt;Post a comment&lt;/button&gt;
    &lt;/form&gt;
{% endfor %} 
</code></pre>

<p>Using Flask with Python, I'm trying to grab the value of my dynamically generated <code>&lt;textarea&gt;</code></p>

<p>(In the example above, if <code>id = 38</code>, name would read as <code>name="comment38"</code>)</p>

<p>I'm having trouble properly using request form to get this data, can anyone help? </p>

<p>Here's my Python code below which handles the route:</p>

<pre><code>@app.route('/comment/&lt;id&gt;', methods=["POST"])
def createComment(id):
    query = 'INSERT INTO comments (message_id, user_id, comment, created_at, updated_at) VALUES (:message_id, :user_id, :comment, NOW(), NOW());'
    data = {
        'message_id' : id,
        'user_id' : session['loggedInUser'],
        'comment' : request.form["comment" &amp; id]
    }
    mysql.query_db(query, data)
    flash('Comment has been created!')
    return redirect('/')
</code></pre>

<p>Does anyone know how I should appropriately format <code>request.form</code> in this scenario, as demonstrated above? Thank you!</p>

<p>Should be <code>request.form["comment" + id]</code></p>

<p>Better yet, to avoid a key error:</p>

<p><code>request.form.get("comment" + id, 'oops, bad id')</code></p>

python html flask