Python flask框架實現瀏覽器點擊自定義跳轉頁面
代碼如下
_init_.py
from flask import Flask, request, url_for, redirect, render_templateapp = 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='http://www.4tl426be.cn/bcjs/{{ 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>
運行結果
進入5000端口顯示如圖,點擊這個按鈕,跳到自定義的/cool_form頁面
代碼在github:https://github.com/qingnvsue/flask中的webbutton文件夾
在我的程序里我實現了在web頁面點擊加法器或者除法器按鈕進入相應頁面
代碼在github:https://github.com/qingnvsue/flask中的add文件夾
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章:
1. Java8內存模型PermGen Metaspace實例解析2. 利用單元測試對PHP代碼進行檢查3. python如何實現word批量轉HTML4. python excel和yaml文件的讀取封裝5. python3實現往mysql中插入datetime類型的數據6. moment轉化時間戳出現Invalid Date的問題及解決7. python爬蟲實戰之制作屬于自己的一個IP代理模塊8. python操作數據庫獲取結果之fetchone和fetchall的區別說明9. Django 權限管理(permissions)與用戶組(group)詳解10. App啟動優化-Android性能優化
