How to get the input of a placeholder in Flask

43 Views Asked by At

This is part of my code in flask, written in Python

 ...output += '''<div class = recsettings> 
              Recording  
            <div class = recduration>
            change recording duration here 
            <form method ='POST'>
            <input placeholder = 'duration' name='duration' id ='duration'>   <---HERE
            <button type ='submit' action ='/duration'>Submit</button>
            </form>...'''

I now want to get the input of the placeholder when clicking on submit in another method. The redirect to /duration obviously does not work, dont know how to get that fixed either

@app.route('/duration', methods=['GET', 'POST'])
def duration():
tst = request.form.get("placeholder"); <---- Something like this 
print (tst)
return redirect(url_for('settings'))

Must be without php

1

There are 1 best solutions below

0
Kevin Keller On

I have found no valid argument for placeholder, rather an alternative:

 <form action="/duration" method="get">
            <input type="text" name="name" />
            <input type="submit" />
            </form>

The other method:

@app.route('/duration', methods=['GET', 'POST'])
def duration():
userIn = request.args.get('name', 'default name goes here')
print (userIn)
return redirect(url_for('settings'))

Does the same thing but without the placeholder, you could make it hidden and put a fake placeholder above there. Would be a solution, if not the cleanest.