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

zwer
  • 24,943
  • 3
  • 48
  • 66
Agella
  • 141
  • 1
  • 1
  • 4
  • Where are you submitting your form from? How are you receiving it? Where are you attempting to obtain the submitted data? So many questions... – zwer Dec 15 '17 at 23:32
  • I use Flask: `@app.route('/schedule/', methods=['POST']) def schedule(adv_id):` – Agella Dec 15 '17 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](https://www.digitalocean.com/community/tutorials/processing-incoming-request-data-in-flask) – JFM Apr 02 '21 at 12:39

1 Answers1

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
zwer
  • 24,943
  • 3
  • 48
  • 66