js檔案: onclick函式
return true時才提交表單,return false時不提交表單。
html檔案:中設定 action和method="post"
中設定 name
主py檔案中:from flask import request, redirect, url_for
def regist():
if request.method == 'get':
return render_template('regist.html')
else:
username = request.form.get(『username』)#獲取form中的資料
判斷使用者名稱是否存在:存在報錯
不存在,存到資料庫中
redirect重定向到登入頁
主py檔案:
from flask importflask,request,render_template,redirect,url_for
from flask_sqlalchemy import
sqlalchemy
import
config
)class
user(db.model):
__tablename__='
user
'id = db.column(db.integer,primary_key=taberror,autoincrement=true)
username = db.column(db.string(20),nullable=false)
password = db.column(db.string(20), nullable=false)
#db.create_all()
##增加
#user = user(username='123456',password = '456789')
#db.session.add(user)
#db.session.commit()##
#查詢#
user =user.query.filter(user.username =='abcdef').first()
#print(user.username,user.password)##
#修改#
user =user.query.filter(user.username =='123456').first()
#user.password='abcdef'
#print(user.username,user.password)
#db.session.commit()##
#刪除#
user =user.query.filter(user.username =='123456').first()
#print(user.username,user.password)
#db.session.delete(user)
#db.session.commit()'/
')defdh():
return render_template('
dh.html')
'/sy/')
defsy():
return render_template('
sy.html')
'/dl/')
defdl():
return render_template('
dl.html')
'/zc/
',methods=['
get','
post'])
defzc():
if request.method == '
get'
:
return render_template("
zc.html")
else
: usern = request.form.get('
name')
password = request.form.get('
password')
user = user.query.filter(user.username ==usern).first()
ifuser:
return
'使用者名稱已存在
'else
: user1 = user(username=usern, password=password)
db.session.add(user1)
db.session.commit()
return redirect(url_for('dl'
))'/fk/')
deffk():
return render_template('
fk.html')
if__name__ == '
__main__':
註冊html:
註冊
<
link
rel="stylesheet"
type
="text/css"
href
="../static/css/zc.css"
>
<
script
src="../static/js/zc.js"
>
script
>
head
>
<
body
>
<
div
class
="box"
>
<
form
action
="}"
method
="post"
>
<
div
class
="container"
style
="width: 400px"
align
="center"
>
<
div
class
="dl"
style
="background-color:#54faff;width: 400px"
><
h2 align
="center"
style
="margin-bottom: 0; width: 400px"
>注 ✉ 冊
h2>
div>
<
div
class
="content"
style
="background-color:#54faff;height:205px;width:400px;float:left;"
>
<
div
class
="xx"
align
="center"
>
<
p>
p>
使用者賬號:
<
input
id="name"
type
="name"
placeholder
="請輸入使用者名稱"
name
="name"
>
<
br>
輸入密碼:
<
input
id="password"
type
="password"
placeholder
="請輸入密碼"
name
="password"
><
br>
確認密碼:
<
input
id="againpass"
type
="password"
placeholder
="請再次輸入密碼"
name
="againpass"
>
<
p>
p>
div>
<
div
id="error_box"
><
br>
div>
<
p>
p>
<
div
class
="an"
>
<
button
onclick
="mylogin()"
>註冊
button
>
<
button
type
="button"
onclick
=window.alert("是否取消註冊!")
>取消
完成註冊功能
js檔案 onclick函式return true時才提交表單,return false時不提交表單。function fnlogin else if ouname.value.charcodeat 0 48 ouname.value.charcodeat 0 57 else for var i 0...
完成註冊功能
js檔案 onclick函式 return true時才提交表單,return false時不提交表單。html檔案 中設定 action和method post 中設定 name 主py檔案中 from flask import request,redirect,url for def regis...
完成註冊功能
1.js檔案 onclick函式 return true時才提交表單,return false時不提交表單。2.html檔案 中設定 action和method post 中設定 name 3.主py檔案中 from flask import request,redirect,url for def...