from flask import flask, request, render_template, url_for
'/')
defindex()
:return render_template(
'index.html'
)# (常用)傳引數的url
# '/product_list'
)def
product_list()
:print
(request)
args = request.args
print
(args)
# 資料庫查詢 pass
return
'商品1,商品2...'
'/login'
)def
login()
:return render_template(
'login.html'
)'/login_submit'
, methods=
['post'
,'get'])
deflogin_submit()
: form = request.form
print
(form)
username = form[
'username'
] password = form[
'password'
]print
(username, password)
# 跟資料庫裡的使用者表做許可權比對或儲存資訊
return
'表單提交完成'
if __name__ ==
'__main__':)
# request: flask框架中全域性變數,儲存著跟請求相關資訊
index頁面
帶引數的請求
login頁面
"zh"
>
"utf-8"
>
登入頁<
/title>
<
/head>
"}" method=
"post"
>
使用者名稱:<
/label>
<
input name=
"username"
type
="email" placeholder=
"請輸入賬戶郵箱"
class=""
>
密碼:<
/label>
<
input name=
"password"
type
="password"
>
<
input
type
="submit" value=
"登入"
>
<
/form>
<
/body>
<
/html>
flask簡介及入門
pip install flask2 建立乙個python工程 建立的flask工程中包含乙個python檔案和乙個html檔案。此處要十分注意html檔案要放在templates資料夾下,此資料夾和python檔案同目錄。3 開始寫案例 1 python檔案 from flask import f...
Linux入門命令及基本操作
linux基礎必懂 eth0,eth1,eth2,lo是什麼意思 eth0,eth1,eth2 代表網絡卡一,網絡卡二,網絡卡三 lo代表127.0.0.1,即localhost ifconfig 檢視ip位址 ip addr 檢視ip位址,2個命令都可以 su 使用者名稱 linux使用者切換,切...
Flask從入門到 「放棄」 2
tips 不能跨瀏覽器 cookie是伺服器通過response進行操作 先建立response物件 flask對cookie內容作了編碼,支援中文 login cookie需要通過response resp response response welcome s username resp.set...