Python flask框架實(shí)現(xiàn)瀏覽器點(diǎ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>
運(yùn)行結(jié)果

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

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



代碼在github:https://github.com/qingnvsue/flask中的add文件夾
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- python flask框架快速入門
- python flask框架詳解
- 利用python實(shí)現(xiàn)后端寫網(wǎng)頁(flask框架)
- python的flask框架難學(xué)嗎
- Python flask框架端口失效解決方案
- Python flask框架如何顯示圖像到web頁面
- python框架flask表單實(shí)現(xiàn)詳解
- Flask框架實(shí)現(xiàn)的前端RSA加密與后端Python解密功能詳解
- Python?flask框架post接口調(diào)用示例
- python flask框架實(shí)現(xiàn)重定向功能示例
- python框架flask知識總結(jié)
相關(guān)文章
Python實(shí)現(xiàn)前端樣式尺寸單位轉(zhuǎn)換
在?Web?前端項(xiàng)目開發(fā)時,樣式尺寸都是以?rpx?為單位,可是?UI?設(shè)計(jì)師在看完開發(fā)后的?UI?,卻要求都以?px?為單位,所以本文就和大家分享一個利用Python就能實(shí)現(xiàn)尺寸單位轉(zhuǎn)換的方法吧2023-06-06
Python爬蟲基于lxml解決數(shù)據(jù)編碼亂碼問題
這篇文章主要介紹了Python爬蟲基于lxml解決數(shù)據(jù)編碼亂碼問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07
python開發(fā)之IDEL(Python GUI)的使用方法圖文詳解
這篇文章主要介紹了python開發(fā)之IDEL(Python GUI)的使用方法,結(jié)合圖文形式較為詳細(xì)的分析總結(jié)了Python GUI的具體使用方法,需要的朋友可以參考下2015-11-11
Python實(shí)現(xiàn)微博動態(tài)圖片爬取詳解
這篇文章主要為大家介紹了如何利用Python中的爬蟲實(shí)現(xiàn)微博動態(tài)圖片的爬取,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起動手試一試2022-03-03
解決pip安裝的第三方包在PyCharm無法導(dǎo)入的問題
這篇文章主要介紹了關(guān)于pip安裝的第三方包在PyCharm無法導(dǎo)入的問題,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
PyTorch中torch.nn.Linear實(shí)例詳解
torch.nn是包含了構(gòu)筑神經(jīng)網(wǎng)絡(luò)結(jié)構(gòu)基本元素的包,在這個包中可以找到任意的神經(jīng)網(wǎng)絡(luò)層,下面這篇文章主要給大家介紹了關(guān)于PyTorch中torch.nn.Linear的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06

