Flag Manager / Python - handling a drop-down list to open different HTML pages

I am learning jar and Python along with HTML and CSS. I have a Flask template for rendering a drop down list.

What I need to do is: when you select a value from the drop-down list, a new HTML page will open corresponding to the selected value (another page for the various options selected).

I tried searching on the Internet, but could not get a lot of resources. When I send a drop-down option with the submit button, the page displays an error message:

Method not allowed

The method is not allowed for the requested URL.

Please guide me to the best possible solution.

Below is my code.

pro.html

    <form name="startpage" method="POST" action="">
    <div class="form-group">
        <div class="input-group">
            <select name = "method_cipher" id = "method_cipher"> 
                <option value="Encrypt">Encrypt</option>
                <option value="Decrypt">Decrypt</option>
            </select>
            <select name = "cipher_type" id = "cipher_type"> 
                <option value="Caesar">Caesar</option>
                <option value="Transposition">Transposition</option>
                <option value="Reverse">Reverse</option>
            </select>
        </div>
        <button type="submit" name="submit" value="success" class="btn btn-default">Submit</button>
    </div>
    </form> 

test.py

    import flask
    APP = flask.Flask(__name__)
    @APP.route('/')
    def index():
        return flask.render_template('pro.html')
    @APP.route("/test" , methods=['GET', 'POST'])
    def test():
        if flask.request.method == 'POST':
            select = flask.request.form.get('method_cipher')
            if(select == 'Encrypt'):
                return flask.render_template('lastpage.html')
    if __name__ == '__main__':
        APP.debug=True
        APP.run()

EDIT - - (HTML-) , , , "" . "lastpage.html", "", . .

+4
2

pro.html URL-, action. , , , /.

. , .

, , URL

<form ... action="/test" ...>

, URL . , jinja, URL- .

<form ... action="{{ url_for("test") }}" ...>

url_for, .

+3

<select onchange ="if (this.value)window.location.href=this.value">
    <option value="/target1">test1<option>
    <option value="/target2">test2<option>
</select>
0

Source: https://habr.com/ru/post/1627738/


All Articles