-1

I can access a value on request.form if I pass a string in directly. However, if I assign the string to a variable and try to use that, it fails. Why doesn't the second print statement below work?

@app.route("/test", methods=['GET', 'POST'])
def test():
    if request.method == 'POST':
        # this works fine
        print(request.form.get('lastname'))
        # this doesn't -- why?
        somevar = '\'lastname\''
        print(request.form.get(somevar))
        return "<p> check console </p>"
    else:
        return render_template('test.html')
<form method="post">
    <input type="text" name="lastname">
    <button type="submit" >Submit</button>
</form>
davidism
  • 121,510
  • 29
  • 395
  • 339

1 Answers1

1

I don't understand why you think you need the quotes at all. You don't:

somevar = 'lastname'
print(request.form.get(somevar))
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895