Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask & Bootstrap remote modal POST

I have a view in Flask that renders remote content of the Bootstrap modal. The content of the modal is a form.

@app.route("/alerts/edit<int:alertID>", methods=["GET", "POST"])

The modal content is being rendered on button press from the parent view:

@app.route("/alerts", methods=["GET"])

My modal has a submit button. When I press the button a POST request is being generated correctly. Unfortunately the POST request is being handled by the parent view ("/alerts") instead of the modal view ("/alerts/edit") giving me "The method POST is not allowed for the requested URL." error.

Is there any way to force remote modal view to process the POST request instead of the parent view?

EDIT: I'm not using AJAX. A snippet from my modal html:

<div class="modal-body">
    <form method="POST">
        <div class="form-group">
            <div class="input-group">
                <span class="input-group-addon" id="sizing-addon2">E-mail</span>
                <input type="text" id="emailAddress" name="emailAddress" value="{{request.form.emailAddress}}" class="form-control" placeholder="{{alert.email}}" aria-describedby="sizing-addon2">
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
            <button class="btn btn-danger" type="submit">Save</button>
        </div>
    </form>
</div>
like image 662
Pavulon Avatar asked Feb 18 '26 20:02

Pavulon


1 Answers

Adding action attribute as suggested by Sean Vieira solved the problem.

like image 157
Pavulon Avatar answered Feb 20 '26 08:02

Pavulon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!