-1

I have a form like this

<form method="GET" action="{{ url_for('model3') }}">
    <div> Choose a Model:
        <select class="form-select" aria-label="Default select example" name="stage">
          <option value="Post Flowering" {% if thing=='Post Flowering' %} selected {% endif %}>Post Flowering</option>
          <option value="Filling" {% if thing=='Filling' %} selected {% endif %}>Filling</option>
          <option value="Filling Ripening" {% if thing=='Filling Ripening' %} selected {% endif %} >Filling-Ripening</option>
          <option value="Ripening" {% if thing=='Ripening' %} selected {% endif %}>Ripening</option>
        </select>
        <input type="submit" value="Submit">
    </div>

then I have route like this

@app.route('/WheatDetect', methods=['POST', 'GET'])
def model3():
    stage = request.args.get('stage')
    print("stage in get-->",stage)
    if request.method == 'POST':
        print("stage in post-->", stage)

the problem is the first print can get what I have from select option while the 2nd print always show none... but I need that value to process my data, but how???

Rebecca Li
  • 21
  • 4
  • because your request method is different. in form you are defining GET while in routing code you are looking into POST – sahasrara62 Oct 07 '21 at 03:21
  • because I need to get that value first, then use it in post...can I have both GET and POST for one form? – Rebecca Li Oct 07 '21 at 13:41

1 Answers1

0
Use
<form method="POST" action="{{ url_for('model3') }}">
Instead of
<form method="GET" action="{{ url_for('model3') }}">

Due to different request method you are not get the value