How do I get the user input submitted on the form to be displayed on a fixed URL?
@app.route('/', methods=['GET','POST'])
def main():
if request.method == 'POST':
msg = request.form['message']
return redirect(url_for('display_msg', msg=msg))
else:
return form
@app.route('/msg')
def display_msg(msg):
return msg
When submitting the form, I get the following error:
TypeError: display_msg() missing 1 required positional argument: 'msg'
This code actually works fine if I initialize msg as a global variable and then do global msg at the top of main, but it will not allow me to pass msg as a parameter to display_msg.
Another way this will work is if I change @app.route('/msg') to @app.route('/<string:msg>'), but this will change the URL to whatever the user submitted on the form which is not what I want. I want the URL to be fixed.