0

making post request to the /scanning page

<form action='scanning' class='main-form needs-validation' method="POST" enctype="multipart/form-data">
    <div class="row">
        <div class="col">
            <div class='form-group'>
                <label for="firstname">Firstname</label>
                <input type="text" name="firstname" id="firstname" class="form-control" required='True'>
            </div>
        </div>

    <div class='text-center'>
        <button type='submit' class='btn btn-outline-success' style='width:700px;margin-top: 30px;'> Submit
        </button>
    </div>



</form>

POST request to /resullcovid

<form action='resultcovid' class='main-form needs-validation' method="POST" enctype="multipart/form-data">

    <div class='form-group'>

        <label  class="custom-file-upload">
        <input type="file" class="form-control" id="file" name='file'/>
        <img class="upload" src="static/upload-solid.svg">
        <p class="textscan" id="scanid">Upload your Chest Scan</p>
        </label>

    </div>

    <div class='text-center'>
        <button type='submit' class='btn btn-outline-success' style='width:700px;margin-top: 30px;'> Submit
        </button>
    </div>

After accessing /resultcovid page when i come backwards it shows confirm form resubmission this webpage required data .....

</form>

@app.route('/scanning', methods=['POST'])
def scanning():
if request.method == 'POST':
    session["firstname"] = request.form['firstname']
    session["lastname"] = request.form['lastname']
    session["email"] = request.form['email']
    session["phone"] = request.form['phone']
    session["gender"] = request.form['gender']
    session["age"] = request.form['age']
    if len(session.get('email', None))!=0:
        return render_template('scan.html')

    else:
        flash('Allowed image types are - png, jpg, jpeg')
        return redirect(request.url)

when i reload the /scanning page the content appears but at the time i come backwards from /resultcovid the problem occurs

@app.route('/resultcovid', methods=['POST'])
def resultc():
if request.method == 'POST':
    file = request.files['file']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        flash('Image successfully uploaded and displayed below')
        img = cv2.imread('static/uploads/'+filename)
        img = cv2.resize(img, (224, 224))
        img = img.reshape(1, 224, 224, 3)
        img = img/255.0
        pred = covid_model.predict(img)
        if pred < 0.5:
            pred = 0
        else:
            pred = 1
        return render_template('resultcovid.html', filename=filename, fn=session.get('firstname', None), ln=session.get('lastname', None), age=session.get('age', None), gender=session.get('gender', None), r=pred)

    else:
        flash('Allowed image types are - png, jpg, jpeg')
        return redirect(request.url)

1 Answers1

0

To understand your problem, you need to know how browsers process the back button. When the back button is clicked on a browser, it returns to the previous request sent from the browser. If the previous request was a GET request, the browser has already cached the response page. So the back button processes that page. If this is a non-GET request, the request may not be cached in the browser. So the back button processes the request again but without your data. So that's why you get that error page.

To understand more about how the back button works in a browser visit: What happens when you go back with the browser?

Fasil K
  • 473
  • 4
  • 17