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.

3
  • 1
    You can't. That isn't sent to your server when the form is submitted. Commented Aug 8, 2015 at 3:53
  • Thanks! Ill use javascript instead like I figured I would need to. Was just curious if there was a possible python answer. Commented Aug 8, 2015 at 3:54
  • Can request.form get the value of 'data-status'? BTW:'data-status' must has a name. Commented Aug 8, 2015 at 4:11

2 Answers 2

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 :)

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

Comments

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?

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.