最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Flask登錄注冊(cè)項(xiàng)目的簡(jiǎn)單實(shí)現(xiàn)

 更新時(shí)間:2021年05月13日 11:52:38   作者:林家小豬  
一個(gè)簡(jiǎn)單的用戶注冊(cè)和登錄的頁(yè)面,涉及到驗(yàn)證,數(shù)據(jù)庫(kù)存儲(chǔ)等等,本文主要介紹了Flask登錄注冊(cè)項(xiàng)目的簡(jiǎn)單實(shí)現(xiàn),從目錄結(jié)構(gòu)開始,感興趣的可以了解一下

本文主要介紹了Flask登錄注冊(cè)項(xiàng)目的簡(jiǎn)單實(shí)現(xiàn),分享給大家,具體如下:

目錄結(jié)構(gòu)

在這里插入圖片描述

配置文件設(shè)計(jì)
/templates/config.py

#數(shù)據(jù)庫(kù)連接配置
import pymysql

conn = pymysql.connect(
        host='192.XXX.XXX.XX',
        port=320xx,
        user='root',
        password='123456',
        database='test_XX'
    )

首頁(yè)/templates/index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
{#    <link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}" rel="external nofollow"  rel="external nofollow" >#}
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet"  type="text/css" href="/static/style.css" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >
    <title>林家小豬測(cè)試小站</title>
</head>
<body>
    <div>
    <h1>您好,{{ username }},歡迎來(lái)到我的小站</h1>
        <a href="{{ url_for('user_login') }}" rel="external nofollow"  rel="external nofollow" >退出</a>
        <br/>
    </div>
</body>
</html>

登錄頁(yè)面/templates/login.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet"  type="text/css" href="/static/style.css" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >
{#    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" rel="external nofollow"  rel="external nofollow"  type="text/css">#}
    <title>登錄</title>
</head>
<body>
    <div>
    <h1>用戶登錄</h1>
    <!--將登陸信息放到一個(gè)form中-->
    <form method="POST">
        <input type="text" name="username" placeholder="請(qǐng)輸入用戶名" />
        <br/>
        <input type="password" name="password" placeholder="請(qǐng)輸入密碼(小于12位)" />
        <br/>
         <!--jinja2的函數(shù)-->
        {% if message %} {{message}} {% endif %}
        <br/>
        <input type="submit" value="登錄" />
        <input type="reset" value="重置" />
        <!--跳轉(zhuǎn)到register的頁(yè)面-->
        <a href="{{ url_for('register') }}" rel="external nofollow" >注冊(cè)</a>
    </form>
    </div>
</body>
</html>

注冊(cè)頁(yè)面/templates/register.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet"  type="text/css" href="/static/style.css" rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >
    <title>注冊(cè)</title>
</head>
<body>
    <div>
    <h1>用戶注冊(cè)</h1>
    <form method="POST">
        <input type="text" name="username" placeholder="請(qǐng)輸入用戶名" />
        <br/>
        <input type="password" name="password" placeholder="請(qǐng)輸入密碼(小于12位)" />
        <br/>
        <!--jinja2的函數(shù)-->
        {% if message %} {{message}} {% endif %}
        <br/>
        <input type="submit" value="注冊(cè)" />
        <input type="reset" value="重置" />
        <a href="{{ url_for('user_login') }}" rel="external nofollow"  rel="external nofollow" >登錄</a>
    </form>
    </div>
</body>
</html>

登錄校驗(yàn) /model/check_login.py

from templates.config import conn
cur = conn.cursor()
def is_null(username,password):
	if(username==''or password==''):
		return True
	else:
		return False


def is_existed(username,password):
	sql="SELECT * FROM user WHERE username ='%s' and password ='%s'" %(username,password)
	cur.execute(sql)
	result = cur.fetchall()
	if (len(result) == 0):
		return False
	else:
		return True

def exist_user(username):
	sql = "SELECT * FROM user WHERE username ='%s'" % (username)
	cur.execute(sql)
	result = cur.fetchall()
	if (len(result) == 0):
		return False
	else:
		return True

注冊(cè)校驗(yàn) /model/regist_login.py

from templates.config import conn

cur = conn.cursor()

def add_user(username, password):
    # sql commands
    sql = "INSERT INTO user(username, password) VALUES ('%s','%s')" %(username, password)
    # execute(sql)
    cur.execute(sql)
    # commit
    conn.commit()  # 對(duì)數(shù)據(jù)庫(kù)內(nèi)容有改變,需要commit()
    conn.close()

最后編輯運(yùn)行文件
app.py

from flask import Flask,render_template
from flask import redirect
from flask import url_for
from flask import request
from model.check_login import is_existed,exist_user,is_null
from model.check_regist import add_user

app = Flask(__name__)

@app.route('/')
def index():
    return redirect( url_for('user_login') )

@app.route('/user_login',methods=['GET','POST'])
def user_login():
    if request.method=='POST':  # 注冊(cè)發(fā)送的請(qǐng)求為POST請(qǐng)求
        username = request.form['username']
        password = request.form['password']
        if is_null(username,password):
            login_massage = "溫馨提示:賬號(hào)和密碼是必填"
            return render_template('login.html', message=login_massage)
        elif is_existed(username, password):
            return render_template('index.html', username=username)
        elif exist_user(username):
            login_massage = "提示:密碼錯(cuò)誤,請(qǐng)輸入正確密碼"
            return render_template('login.html', message=login_massage)
        else:
            login_massage = "不存在該用戶"
            return render_template('login.html', message=login_massage)
    return render_template('login.html')

@app.route("/regiser",methods=["GET", 'POST'])
def register():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        if is_null(username,password):
            login_massage = "溫馨提示:賬號(hào)和密碼是必填"
            return render_template('register.html', message=login_massage)
        elif exist_user(username):
            return redirect(url_for('user_login'))
        else:
            add_user(request.form['username'], request.form['password'] )
            return render_template('index.html', username=username)
    return render_template('register.html')



if __name__=="__main__":
    app.run()

到此這篇關(guān)于Flask登錄注冊(cè)項(xiàng)目的簡(jiǎn)單實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Flask登錄注冊(cè)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 如何基于pandas讀取csv后合并兩個(gè)股票

    如何基于pandas讀取csv后合并兩個(gè)股票

    這篇文章主要介紹了如何基于pandas讀取csv后合并兩個(gè)股票,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • graphviz 最新安裝教程適用初學(xué)者

    graphviz 最新安裝教程適用初學(xué)者

    Graphviz 是一個(gè)自動(dòng)排版的作圖軟件,可以生成 png pdf 等格式,這篇文章主要介紹了graphviz 2022最新安裝教程適用初學(xué)者,需要的朋友可以參考下
    2023-02-02
  • Python 中 -m 的典型用法、原理解析與發(fā)展演變

    Python 中 -m 的典型用法、原理解析與發(fā)展演變

    這篇文章主要介紹了Python 中 -m 的典型用法、原理解析與發(fā)展演變,需要的朋友可以參考下
    2019-11-11
  • python的slice notation的特殊用法詳解

    python的slice notation的特殊用法詳解

    今天小編就為大家分享一篇python的slice notation的特殊用法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-12-12
  • 分享Python獲取本機(jī)IP地址的幾種方法

    分享Python獲取本機(jī)IP地址的幾種方法

    這篇文章主要介紹了分享Python獲取本機(jī)IP地址的幾種方法,分享了使用專用網(wǎng)站、使用自帶socket庫(kù)、使用第三方netifaces庫(kù)等方式們需要的小伙伴可以參考一下
    2022-03-03
  • keras實(shí)現(xiàn)調(diào)用自己訓(xùn)練的模型,并去掉全連接層

    keras實(shí)現(xiàn)調(diào)用自己訓(xùn)練的模型,并去掉全連接層

    這篇文章主要介紹了keras實(shí)現(xiàn)調(diào)用自己訓(xùn)練的模型,并去掉全連接層,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-06-06
  • python利用lxml庫(kù)剩下操作svg圖片

    python利用lxml庫(kù)剩下操作svg圖片

    在大多數(shù)場(chǎng)景中,我們都用?lxml?庫(kù)解析網(wǎng)頁(yè)源碼,但你是否知道,lxml?庫(kù)也是可以操作?svg?圖片的。本文就來(lái)和大家聊聊具體操作方法,希望對(duì)大家有所幫助
    2023-01-01
  • Python實(shí)現(xiàn)LRU算法

    Python實(shí)現(xiàn)LRU算法

    這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)LRU緩存置換算法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • 使用Python 自動(dòng)生成 Word 文檔的教程

    使用Python 自動(dòng)生成 Word 文檔的教程

    今天小編就為大家分享一篇使用Python 自動(dòng)生成 Word 文檔的教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-02-02
  • python用post訪問(wèn)restful服務(wù)接口的方法

    python用post訪問(wèn)restful服務(wù)接口的方法

    今天小編就為大家分享一篇python用post訪問(wèn)restful服務(wù)接口的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12

最新評(píng)論

柳河县| 永川市| 龙南县| 铜鼓县| 祁门县| 兴文县| 建昌县| 临沂市| 宣武区| 文登市| 大埔县| 绥江县| 五台县| 永泰县| 黎平县| 曲靖市| 双流县| 马尔康县| 葫芦岛市| 太湖县| 武清区| 宁夏| 吴堡县| 宁陕县| 康定县| 绥德县| 黄梅县| 黄浦区| 时尚| 临澧县| 亳州市| 中超| 昭通市| 涟水县| 绵阳市| 锡林浩特市| 翁牛特旗| 巍山| 安化县| 米林县| 抚顺市|