3

Hopefully there is a very simple answer to this problem. I want to get data from a POST in flask that is not your standard textfield value. The trick to this is that I want to try and find a solution without using javascript, I could easily do that but Im attempting to only use python.

This is not my specific example but instead a simplified one.

I want to get the value of "data-status"

<form action="/myurl/" method="post">
    <div data-status="mydatahere" class="classname"></div>
</form>

Python

@app.route('/myurl/', methods=['POST'])
def myurl():
    #python to get 'data-status' value here.

Thanks so much to anyone that can provide an answer.

Chris Burgin
  • 216
  • 3
  • 13

2 Answers2

3

You could pass it in as a URL parameter via the action attribute of your form, e.g.:

<form action="/myurl/?data-status=mydatahere" method="post">
    <div class="classname"></div>
</form>

And then pick it up in flask like so:

@app.route('/myurl/', methods=['POST'])
def myurl():
    #python to get 'data-status' value here as my_var variable:
    my_var = request.args.get('data-status')

Not sure if this works in your situation but it is how I solved a similar problem for myself :)

Zoe stands with Ukraine
  • 25,310
  • 18
  • 114
  • 149
jeffmjack
  • 472
  • 4
  • 14
1

You can't.

If you're for some reason unable to change your HTML, I suggest you to make it on submit event.

Take a look at this other question: How to add additional fields to form before submit?

Community
  • 1
  • 1
iurisilvio
  • 4,727
  • 1
  • 26
  • 31