国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

Vue和Flask實現簡單的登錄驗證跳轉

來源:懂視網 責編:小OO 時間:2020-11-27 20:05:58
文檔

Vue和Flask實現簡單的登錄驗證跳轉

文件位置。login.html。<;,{ username: this.username.password: this.password }).then(function (response) { console.log(response.status) // 其實是應該走后臺路由 if(parseInt(response.status) === 200){ window.location.href = ';index';} }).catch(function (error) { console.log(error.response) }) } } })<;/script>;<;/body>;<;/html>;。
推薦度:
導讀文件位置。login.html。<;,{ username: this.username.password: this.password }).then(function (response) { console.log(response.status) // 其實是應該走后臺路由 if(parseInt(response.status) === 200){ window.location.href = ';index';} }).catch(function (error) { console.log(error.response) }) } } })<;/script>;<;/body>;<;/html>;。
本文主要介紹了Vue+Flask實現簡單的登錄驗證跳轉的示例代碼,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧,希望能幫助到大家。

文件位置:

login.html

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Login</title>

 <script type="text/javascript" src="../static/vue.js"></script>
 <script type="text/javascript" src="../static/axios.js"></script>

</head>
<body>

<p id="login">
 <form action="#" novalidate>
 <label for="username">Username</label>
 <input type="text" name="username" id="username" placeholder="Enter your Name" v-model="username"><br>
 <label for="password">Password</label>
 <input type="text" name="password" id="password" placeholder="Enter your Password" v-model="password"><br>
 <br>

 <button type="button" v-on:click="login">Apply</button>
 </form>
</p>


<script type="text/javascript">
 var login = new Vue({
 el: '#login',
 data:{
 username: '',
 password: ''
 },
 methods: {
 login: function () {
 axios.post('http://127.0.0.1:5000/login',{
 username: this.username,
 password: this.password
 }).then(function (response) {
 console.log(response.status)
 // 其實是應該走后臺路由
 if(parseInt(response.status) === 200){
 window.location.href = 'index'
 }
 }).catch(function (error) {
 console.log(error.response)
 })

 }
 }
 })
</script>

</body>
</html>

index.html

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Index</title>
</head>
<body>
 <h1>Hello,This is Index Page!</h1>
</body>
</html>

Login.py

# -*- coding: utf-8 -*-

from flask import Flask, request, session, redirect, url_for, render_template, make_response, jsonify
app = Flask(__name__)


@app.route('/login', methods=('GET', 'POST'))
def login():
 if request.method == 'POST':
 session['username'] = request.json.get('username')
 session['password'] = request.json.get('password')
 # 登錄成功,則跳轉到index頁面
 return jsonify({'code': 200, 'token': "123456"})
 # 登錄失敗,跳轉到當前登錄頁面
 return render_template('login.html')


@app.route('/index')
def index():
 # 如果用戶名和密碼都存在,則跳轉到index頁面,登錄成功
 if 'username' in session and 'password' in session:
 return render_template('index.html')
 # 否則,跳轉到login頁面
 return redirect(url_for('login'))


@app.route('/logout')
def logout():
 session.pop('username', None)
 session.pop('password', None)
 return redirect(url_for('login'))


# set the secret key. keep this really secret:
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'


if __name__ == '__main__':
 app.run(debug=True)

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

Vue和Flask實現簡單的登錄驗證跳轉

文件位置。login.html。<;,{ username: this.username.password: this.password }).then(function (response) { console.log(response.status) // 其實是應該走后臺路由 if(parseInt(response.status) === 200){ window.location.href = ';index';} }).catch(function (error) { console.log(error.response) }) } } })<;/script>;<;/body>;<;/html>;。
推薦度:
標簽: VUE fl flask
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 国产成人精品日本亚洲网址 | 国产精品成人久久久 | 国产精品毛片va一区二区三区 | 日韩欧美综合在线 | 国产免费高清视频在线观看不卡 | 国产亚洲一欧美一区二区三区 | 午夜欧美性视频在线播放 | 欧美日韩国产在线播放 | 日韩欧美精品综合一区二区三区 | 国产欧美成人一区二区三区 | 黄色a一级视频 | 国产精品亚洲一区二区在线观看 | 国产精品久久久久国产精品 | 国产观看 | 91精品国产高清久久久久久io | 亚洲欧美日韩国产 | 日韩在线欧美在线 | 91精品一区二区三区在线观看 | 国产一区二区三区免费视频 | 在线播放国产视频 | 又黄又爽视频在线观看 | 日韩欧美一区二区三区在线播放 | 欧美区一区二区三 | 色妞综合| 精品国产电影在线看免费观看 | www.久久99| 亚洲视频一区二区 | 亚洲美女一区二区三区 | 大色欧美| xxxxx欧美 | 国产在线视频一区 | 国产精品网址 | 91热国产 | 国产亚洲欧美精品久久久 | 国产成人无精品久久久久国语 | 国产伦精品一区二区三区 | 久久91精品国产一区二区 | 久久国产成人午夜aⅴ影院 久久国产精品成人免费古装 | 国产成人精品日本亚洲语音1 | 亚洲国产天堂久久九九九 | 精品在线免费观看 |