Python flask框架實現(xiàn)瀏覽器點擊自定義跳轉(zhuǎn)頁面
代碼如下
_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') }}" rel="external nofollow" >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>
運行結(jié)果

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

代碼在github:https://github.com/qingnvsue/flask中的webbutton文件夾
在我的程序里我實現(xiàn)了在web頁面點擊加法器或者除法器按鈕進(jìn)入相應(yīng)頁面



代碼在github:https://github.com/qingnvsue/flask中的add文件夾
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python opencv實現(xiàn)gif圖片分解的示例代碼
這篇文章主要介紹了python opencv實現(xiàn)gif圖片分解的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
Python+Socket實現(xiàn)基于UDP協(xié)議的局域網(wǎng)廣播功能示例
這篇文章主要介紹了Python+Socket實現(xiàn)基于UDP協(xié)議的局域網(wǎng)廣播功能,結(jié)合實例形式分析了Python+socket實現(xiàn)UDP協(xié)議廣播的客戶端與服務(wù)器端功能相關(guān)操作技巧,需要的朋友可以參考下2017-08-08
python中自定義異常/raise關(guān)鍵字拋出異常的案例解析
在編程過程中合理的使用異??梢允沟贸绦蛘5膱?zhí)行,本篇文章給大家介紹python中自定義異常/raise關(guān)鍵字拋出異常案例解析,需要的朋友可以參考下2024-01-01
Python實現(xiàn)圖書管理系統(tǒng)設(shè)計
這篇文章主要為大家詳細(xì)介紹了Python實現(xiàn)圖書管理系統(tǒng)設(shè)計,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-03-03

