13

I submit form using POST method. Form has one input field: time.

I tried to check if exist parameter:

if 'time' in request.data:
   pass

But it does not work

3
  • Where are you submitting your form from? How are you receiving it? Where are you attempting to obtain the submitted data? So many questions... Commented Dec 15, 2017 at 23:32
  • I use Flask: @app.route('/schedule/<int:adv_id>', methods=['POST']) def schedule(adv_id): Commented Dec 15, 2017 at 23:35
  • The code that will handle your arguments can read in the time key by using either request.data.get('time') or request.data['time']. By calling request.data.get('time'), the application will continue to run if the language key doesn’t exist in the URL. In that case, the result of the method will be None. So you need t = request.data.get('time') if t: pass Source: digitalocean.com Commented Apr 2, 2021 at 12:39

1 Answer 1

26

You should use request.form if you're posting your data as a regular POST body query, i.e.:

@app.route('/schedule/<int:adv_id>', methods=['POST'])
def schedule(adv_id):
    if "time" in request.form:
        pass  # do whatever you want with it
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, how to check if value not null?
Not null, or not posted at all? A general concept would be: if request.form.get("time", None): ...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.