Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

POST request to Flask Blueprint api not working

I am trying to execute a form POST request. The request is received at the route api function but the POST condition is not executing.

Code

<form class="pt-2 pb-4" action = "{{ url_for('data_sources_api.testfn') }}" method = "POST">
    <div class="row">
        <div class="col-md-4 mb-3">
            <label for="url" class="form-label">URL</label>
            <input type="text" class="form-control" id="url" name="url" aria-describedby="emailHeurllp"
                placeholder="Enter new events top domain source url">
        </div>
        <div class="col-md-4 mb-3">
            <label for="name" class="form-label">Name</label>
            <input type="text" class="form-control" id="name" name="name" placeholder="Enter Organization Name">
        </div>
        <div class="col-md-12">
            <button type="button" class="btn btn-secondary mr-2" value="submit" name = "submit">Submit</button>
        </div>
    </div>
</form>

Flask Code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@data_sources_api.route('/login/test', methods=["GET", "POST"])
def testfn():
    # Check if user is loggedin
    if loggedin():
        # User is loggedin, render the home page
        if request.method == 'POST':
            print("POST Request Received")
            result = request.form
        return render_template('users/data-sources.html', role=session['role'])
    return redirect(url_for('account_api.login'))

The request received is GET when i click the submit button and not POST 🙁

Thanks in advance

>Solution :

I think the problem is with button. Replace the button with input type="submit":

<input type="submit" value="Submit">

Here is the example of Django form.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading