python的flask框架下實現在瀏覽器點一個按鈕,頁面跳到你自定義的其他頁面


_init_.py

from flask import Flask, request, url_for, redirect, render_template

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/cool_form', methods=['GET', 'POST'])
def cool_form():
    if request.method == 'POST':
        # do stuff when the form is submitted

        # redirect to end the POST handling
        # the redirect can be to the same route or somewhere else
        return redirect(url_for('index'))

    # show the form, it wasn't submitted
    return render_template('cool_form.html')

index.html

<!doctype html>
<html>
<body>
    <p><a href="{{ url_for('cool_form') }}">Check out this cool form!</a></p>
</body>
</html>

cool_form.html

<!doctype html>
<html>
<body>
    <form method="post">
        <button type="submit">Do it!</button>
    </form>
</html>

運行結果

進入5000端口顯示如圖,點擊這個按鈕,跳到自定義的/cool_form頁面

代碼在github:https://github.com/qingnvsue/flask 中的webbutton文件夾

 

 

 在我的程序里我實現了在web頁面點擊加法器或者除法器按鈕進入相應頁面

 

 

 

 

 

 代碼在github:https://github.com/qingnvsue/flask 中的add文件夾


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM