tornado_登錄頁面(案例)

目錄

1.基礎知識?編輯

2.腳手架(模版)

3.登錄流程圖(processon)

4.登錄表單

4.1后(返回值)任何值:username/password

(4.1.1)app.py

(4.1.2)表單.html

(4.3)login.py(沒啥用,充當第二頁的跳轉頁面)

4.1.3返回 用戶名+密碼 結果

4.2寫死 admin/123 ##,返回index首頁

(4.2.1app.py)用戶名/密碼正確,返回index首頁,否則,返回error404_n頁面

(4.2.2index.html)首頁

(4.2.3error.html)404_n

5.注冊表單(后臺)?

(5.1 app.py的注冊部分)

(5.2 register.html 注冊表)

?報錯:

**404:沒有寫路由

**500:目錄結構 / 內容錯誤


1.基礎知識

Linux寫法

2.腳手架(模版)

(1)打印hello world

#!/usr/bin/env python
#-*- coding:utf-8 -*-from tornado import web, httpserver, ioloop
#1.邏輯處理模塊
class LoginHandler(web.RequestHandler):def get(self,*args,**kwargs):self.write("hello world")#self.render("login.html")#2.路由
application=web.Application([(r"/login",LoginHandler),])#3.socket服務端
if __name__=='__main__':http_server=httpserver.HTTPServer(application)print("http://127.0.0.1:8080/login")http_server.listen(8080)ioloop.IOLoop.current().start()

(2)網頁login

1).py

 self.render("login.html")   #渲染

2)? ?.html?

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><h1 style="color:pink;">hi</h1>
</body>
</html>

**報錯500,目錄結構

3.登錄流程圖(processon)

4.登錄表單

4.1后(返回值)任何值:username/password

**基于這個前端頁面,用tornado框架,寫后端api接口代碼,調用get、post請求。

(4.1.1)app.py
#!/usr/bin/env python
#-*- coding:utf-8 -*-from tornado import web, httpserver, ioloop
#1.邏輯處理模塊
class LoginHandler(web.RequestHandler):def get(self,*args,**kwargs):#self.write("hello world")#返回登錄頁面#self.render("login.html")   #渲染self.render("表單.html")   #渲染def post(self,*args,**kwargs):#驗證用戶密碼(獲取)username=self.get_argument("username")passward=self.get_argument("password")print(username,passward)#設置
setting={'template_path':'template'
}#2.路由
application=web.Application([(r"/login",LoginHandler),   #這個對應著/login],**setting)#3.socket服務端
if __name__=='__main__':http_server=httpserver.HTTPServer(application)print("http://127.0.0.1:8080/login")http_server.listen(8080)ioloop.IOLoop.current().start()
(4.1.2)表單.html
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>表單</title>
</head>
<body><h2>表單</h2><form action="/login" method="post">    <!--這里的、login對應著app.py里面的路由-->賬號:<input type="text" name="username"/><br/>密碼:<input type="password" name="password"/><br/><input type="submit" value="登錄"/></form></body>
</html>
(4.3)login.py(沒啥用,充當第二頁的跳轉頁面)
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><h1 style="color:pink;">hi</h1>
</body>
</html>
4.1.3返回 用戶名+密碼 結果

4.2寫死 admin/123 ##,返回index首頁

(4.2.1app.py)用戶名/密碼正確,返回index首頁,否則,返回error404_n頁面
#!/usr/bin/env python
#-*- coding:utf-8 -*-from tornado import web, httpserver, ioloop
#1.邏輯處理模塊
#登錄
class LoginHandler(web.RequestHandler):def get(self,*args,**kwargs):#self.write("hello world")#返回登錄頁面#self.render("login.html")   #渲染self.render("表單.html")   #渲染def post(self,*args,**kwargs):#驗證用戶密碼(獲取)username=self.get_argument("username")passward=self.get_argument("password")#print(username,passward)#寫死,if正確進入if username=='admin' and passward=='123':self.redirect('/index')##跳轉else:self.render('error.html')##跳轉首頁面模塊
class IndexHandler(web.RequestHandler):def get(self,*args,**kwargs):self.render("index.html")#設置
setting={'template_path':'template'
}#2.路由
application=web.Application([(r"/login",LoginHandler),   #這個對應著/login(r"/index",IndexHandler),##首頁面路由],**setting)#3.socket服務端
if __name__=='__main__':http_server=httpserver.HTTPServer(application)print("http://127.0.0.1:8080/login")http_server.listen(8080)ioloop.IOLoop.current().start()
(4.2.2index.html)首頁
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>login2</title>
</head>
<body><h2 style="color:pink">I am index</h2></body>
</html>
(4.2.3error.html)404_n
    <h2 style="color:purple">輸入錯誤404_n</h2>

5.注冊表單(后臺)?

(5.1 app.py的注冊部分)
###全局變量
user_info={}
###注冊 post獲取
class RegisterHandler(web.RequestHandler):def post(self,*args,**kwargs):email = self.get_argument("emial")username = self.get_argument("username")password = self.get_argument("password")password1 = self.get_argument("password1")access = self.get_argument("access", default=None)if access:  #用email當keyif password==password1:UNER_INFO[email]={"username":username,"password":password,}self.render("success.html",info={'stauts':True,'info':'注冊成功','second':3})else:self.render('error.html', info={'status': False,'info': '密碼不一致','second': 3,  # 倒計時3秒'url': '/register'})  # 跳轉else:self.render('error.html', info={'status': False,'info': '請同意協議','second': 3,  # 倒計時3秒'url':'/register'})  # 跳轉def get(self,*args,**kwargs):self.render("表單.html",type='register')###收到數據后要存儲起來
###用數據庫/全局變量(√)上面
(5.2 register.html 注冊表)
<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>用戶注冊</title><style>body {font-family: Arial, sans-serif;background-color: #f4f4f4;display: flex;justify-content: center;align-items: center;height: 100vh;margin: 0;}.container {background-color: white;padding: 20px;border-radius: 5px;box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);width: 300px;}.container h2 {text-align: center;margin-bottom: 20px;}.form-group {margin-bottom: 15px;}.form-group label {display: block;margin-bottom: 5px;}.form-group input[type="email"],.form-group input[type="text"],.form-group input[type="password"] {width: 100%;padding: 8px;box-sizing: border-box;border: 1px solid #ccc;border-radius: 4px;}.form-group input[type="checkbox"] {margin-right: 5px;}.form-group button {width: 100%;padding: 10px;background-color: #4CAF50;color: white;border: none;border-radius: 4px;cursor: pointer;}.form-group button:hover {background-color: #45a049;}.form-group .reset {background-color: #ccc;}.form-group .reset:hover {background-color: #bbb;}</style>
</head>
<body><div class="container"><h2>用戶注冊</h2><form><div class="form-group"><label for="email">郵箱</label><input type="email" id="email" name="email" required></div><div class="form-group"><label for="username">用戶名</label><input type="text" id="username" name="username" value="admin" required></div><div class="form-group"><label for="password">密碼</label><input type="password" id="password" name="password" required></div><div class="form-group"><label for="confirm-password">確認密碼</label><input type="password" id="confirm-password" name="confirm-password" required></div><div class="form-group"><input type="checkbox" id="agreement" name="agreement" required><label for="agreement">接受 用戶協議</label></div><div class="form-group"><button type="reset" class="reset">重置</button><button type="submit">注冊</button></div></form></div>
</body>
</html>

?報錯:

**404:沒有寫路由

**500:目錄結構 / 內容錯誤

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/78971.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/78971.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/78971.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Android學習總結之自定義view設計模式理解

面試題 1&#xff1a;請舉例說明自定義 View 中模板方法模式的應用 考點分析 此問題主要考查對模板方法模式的理解&#xff0c;以及該模式在 Android 自定義 View 生命周期方法里的實際運用。 回答內容 模板方法模式定義了一個操作的算法骨架&#xff0c;把一些步驟的實現延…

【Scrapy】簡單項目實戰--爬取dangdang圖書信息

目錄 一、基本步驟 1、新建項目 &#xff1a;新建一個新的爬蟲項目 2、明確目標 &#xff08;items.py&#xff09;&#xff1a;明確你想要抓取的目標 3、制作爬蟲 &#xff08;spiders/xxspider.py&#xff09;&#xff1a;制作爬蟲開始爬取網頁 4、存儲內容 &#xff08;p…

開源CMS系統的SEO優化功能主要依賴哪些插件?

在當今互聯網時代&#xff0c;搜索引擎優化&#xff08;SEO&#xff09;是網站獲取流量的核心手段之一。開源內容管理系統&#xff08;CMS&#xff09;因其靈活性和豐富的插件生態&#xff0c;成為許多開發者和企業的首選。本文將以主流開源CMS為例&#xff0c;深入解析其SEO優…

在 JMeter 中使用 BeanShell 獲取 HTTP 請求體中的 JSON 數據

在 JMeter 中&#xff0c;您可以使用 BeanShell 處理器來獲取 HTTP 請求體中的 JSON 數據。以下是幾種方法&#xff1a; 方法一&#xff1a;使用前置處理器獲取請求體 如果您需要在發送請求前訪問請求體&#xff1a; 添加一個 BeanShell PreProcessor 到您的 HTTP 請求采樣器…

在 WSL (Windows Subsystem for Linux) 中配置和安裝 Linux 環境

在 WSL (Windows Subsystem for Linux) 中配置和安裝 Linux 環境 WSL 允許你在 Windows 上運行 Linux 環境&#xff0c;以下是詳細的配置和安裝指南。 1. 安裝前的準備工作 系統要求 Windows 10 版本 2004 及更高版本(內部版本 19041 及更高版本)或 Windows 11 64 位系統 虛…

AlphaFold蛋白質結構數據庫介紹

AlphaFold Protein Structure Database (AlphaFold DB) 是 DeepMind + EMBL-EBI 合作開發的公開蛋白質結構預測數據庫,是利用 AlphaFold2/AlphaFold3 AI模型 預測的全基因組級蛋白質三維結構庫。 網址: https://alphafold.ebi.ac.uk 項目內容主辦單位DeepMind + EMBL-EBI上線…

3.2goweb框架GORM

GORM 是 Go 語言中功能強大的 ORM&#xff08;對象關系映射&#xff09;框架&#xff0c;支持 MySQL、PostgreSQL、SQLite、SQL Server 等主流數據庫。以下是 GORM 的核心概念和用法詳解&#xff1a; ??一、基礎入門?? 1. 安裝 go get -u gorm.io/gorm go get -u gorm.io…

第三部分:特征提取與目標檢測

像邊緣、角點、特定的紋理模式等都是圖像的特征。提取這些特征是許多計算機視覺任務的關鍵第一步&#xff0c;例如圖像匹配、對象識別、圖像拼接等。目標檢測則是在圖像中找到特定對象&#xff08;如人臉、汽車等&#xff09;的位置。 本部分將涵蓋以下關鍵主題&#xff1a; …

Canvas基礎篇:圖形繪制

Canvas基礎篇&#xff1a;圖形繪制 圖形繪制moveTo()lineTo()lineTo繪制一條直線代碼示例效果預覽 lineTo繪制平行線代碼示例效果預覽 lineTo繪制矩形代碼示例效果預覽 arc()arc繪制一個圓代碼實現效果預覽 arc繪制一段弧代碼實現效果預覽 arcTo()rect()曲線 結語 圖形繪制 在…

瑞芯微芯片算法開發初步實踐

文章目錄 一、算法開發的一般步驟1.選擇合適的深度學習框架2.對于要處理的問題進行分類&#xff0c;是回歸問題還是分類問題。3.對數據進行歸納和整理4.對輸入的數據進行歸一化和量化&#xff0c;保證模型運行的效率和提高模型運行的準確度5.在嵌入式處理器上面運行模型&#x…

計算機畢業設計--基于深度學習(U-Net與多尺度ViT)的模糊車牌圖像清晰化復原算法設計與實現(含Github代碼+Web端在線體驗鏈接)

基于深度學習的U-Net架構下多尺度Transformer車牌圖像去模糊算法設計與實現 如果想對舊照片進行模糊去除&#xff0c;劃痕修復、清晰化&#xff0c;請參考這篇CSDN作品&#x1f447; 計算機畢業設計–基于深度學習的圖像修復&#xff08;清晰化劃痕修復色彩增強&#xff09;算…

(Go Gin)Gin學習筆記(四)Gin的數據渲染和中間件的使用:數據渲染、返回JSON、淺.JSON()源碼、中間件、Next()方法

1. 數據渲染 1.1 各種數據格式的響應 json、結構體、XML、YAML類似于java的properties、ProtoBuf 1.1.1 返回JSON package mainimport ("github.com/gin-gonic/gin""net/http" )func main() {r : gin.Default()r.POST("/demo", func(res *gi…

實驗:串口通信

/************************************************* * AT89C52 串口通信實驗&#xff08;實用修正版&#xff09; * 特點&#xff1a; * 1. 解決所有編譯警告 * 2. 保持代碼簡潔 * 3. 完全功能正常 ************************************************/ #include <re…

智駕賽道的諾曼底登陸,Momenta上海車展雄起

作者 |蘆葦 編輯 |德新 今年的上海車展依舊熱鬧非凡&#xff0c;但火熱的車市背后也是暗流涌動。尤其對智駕供應商而言&#xff0c;「智駕平權」帶動了解決方案大量上車&#xff0c;各大主機廠紛紛選定各自的主要供應商&#xff0c;這也意味著賽道機會越發收斂。 正如汽車品牌…

Java 事務詳解

目錄 一、事務的基本概念1.1 什么是事務?1.2 事務的 ACID 特性二、Java 事務管理的實現方式2.1 JDBC 事務管理2.2 Spring 事務管理2.2.1 添加 Spring 依賴2.2.2 配置 Spring 事務管理2.2.3 使用 Spring 事務注解三、事務隔離級別四、最佳實踐4.1 盡量縮小事務范圍4.2 合理選擇…

DirectX12(D3D12)基礎教程七 深度模板視圖\剔除\謂詞

本章主要講遮擋&#xff0c;作者認為比較復雜有難度的知識點&#xff0c;作為基礎教程不會深入講解。 GPU渲染管線 主要包括以下階段 輸入裝配&#xff08;IA&#xff09;&#xff1a;讀取頂點數據 &#xff0c;定義頂點數據結構頂點著色&#xff08;VS&#xff09;&#xf…

溫補晶振(TCXO)穩定性優化:從實驗室到量產的關鍵技術

在現代通信、航空航天、5G基站等對頻率穩定性要求極高的領域&#xff0c;溫補晶振&#xff08;TCXO&#xff09;扮演著不可或缺的角色。其穩定性直接影響系統的性能與可靠性&#xff0c;因此&#xff0c;對TCXO穩定性優化技術的研究與實踐至關重要。 一、溫度補償算法&#xff…

C++,設計模式,【建造者模式】

文章目錄 通俗易懂的建造者模式&#xff1a;手把手教你造電腦一、現實中的建造者困境二、建造者模式核心思想三、代碼實戰&#xff1a;組裝電腦1. 產品類 - 電腦2. 抽象建造者 - 裝機師傅3. 具體建造者 - 電競主機版4. 具體建造者 - 辦公主機版5. 指揮官 - 裝機總控6. 客戶端使…

前端基礎之《Vue(13)—重要API》

重要的API 一、nextTick() 1、寫法 Vue.$nextTick()或者this.$nextTick() 原因&#xff1a; set操作代碼是同步的&#xff0c;但是代碼背后的行為是異步的。set操作修改聲明式變量&#xff0c;觸發re-render生成新的虛擬DOM&#xff0c;進一步執行diff運算&#xff0c;找到…

Windows 中搭建 browser-use WebUI 1.4

目錄 1. 背景介紹2. 搭建過程3. 補充 1. 背景介紹 背景&#xff1a;想要在 Windows 中復現 browser-use WebUI pickle反序列化漏洞&#xff0c;該漏洞在 v1.7 版本中已經修復&#xff0c;所以需要搭建 小于 1.7 版本的環境&#xff0c;我這里搭建的是 1.4 版本。 項目地址&am…