Python flask框架實(shí)現(xiàn)瀏覽器點(diǎn)擊自定義跳轉(zhuǎn)頁(yè)面
代碼如下
_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.hdgsjgj.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>
運(yùn)行結(jié)果
進(jìn)入5000端口顯示如圖,點(diǎn)擊這個(gè)按鈕,跳到自定義的/cool_form頁(yè)面
代碼在github:https://github.com/qingnvsue/flask中的webbutton文件夾
在我的程序里我實(shí)現(xiàn)了在web頁(yè)面點(diǎn)擊加法器或者除法器按鈕進(jìn)入相應(yīng)頁(yè)面
代碼在github:https://github.com/qingnvsue/flask中的add文件夾
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Spring security 自定義過(guò)濾器實(shí)現(xiàn)Json參數(shù)傳遞并兼容表單參數(shù)(實(shí)例代碼)2. Java8內(nèi)存模型PermGen Metaspace實(shí)例解析3. python tkinter實(shí)現(xiàn)下載進(jìn)度條及抖音視頻去水印原理4. ASP.NET MVC使用正則表達(dá)式驗(yàn)證手機(jī)號(hào)碼5. 一文搞懂 parseInt()函數(shù)異常行為6. Python 有可能刪除 GIL 嗎?7. Python使用sftp實(shí)現(xiàn)上傳和下載功能8. python捕獲警告的三種方法9. python 統(tǒng)計(jì)list中各個(gè)元素出現(xiàn)的次數(shù)的幾種方法10. Python基于百度AI實(shí)現(xiàn)抓取表情包
