0

I know I can easily extract data from html input tag using request.form['email'] after POST method. Is there a way to populate this particular input tag with something like:

request.form['email'] = current_user.email

which obviously throws 'ImmutableMultiDict' objects are immutable? (Without using FlaskWTF). Any help would be much appreciated!

2

2 Answers 2

1

You can overwrite request.form :

from werkzeug.datastructures import ImmutableMultiDict
from flask import Flask,request

app = Flask(__name__)

@app.route('/')
def hello_world():
    # overwrite request.form to add 'email'
    tempo_form_dict = request.form.to_dict()
    tempo_form_dict['email'] = 'Hello@World'
    request.form = ImmutableMultiDict(tempo_form_dict)
    
    ## Then you can use request.form as it was inputted...
    
    return str(request.form)

if __name__ == '__main__':
    app.run(debug=True,host=None,port=5000)

a linked question: Python Werkzeug: modify Request values (forms and args) prior to retrieval

Sign up to request clarification or add additional context in comments.

Comments

0

Actually, this could be easily done using value attribute, e.g.:

<input class="email" name="email" value="{{ current_user.email }}" required/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.