db.py

  

import MySQLdb
conn = MySQLdb.connect('localhost', 'root', '', 'test1')
cur = conn.cursor() def addUser (username,password):
sql="insert into user (username,password) VALUES ('%s','%s')"%(username,password)
cur.execute(sql)
conn.commit()
conn.close() def isExisted(username,password):
sql = "select * from user where username='%s' and password = '%s' " %(username,password)
cur.execute(sql)
result = cur.fetchall()
print result
if len(result)==0:
return False
else:
return True

main.py

  

from flask import Flask,url_for
from flask import request
from flask import render_template
from flask import redirect
from db import *
app = Flask(__name__) @app.route('/login',methods=['GET','POST'])
def login():
if request.method =='POST':
username=request.form.get('username')
password=request.form.get('password')
if isExisted(username,password):
message = "login success"
return render_template('index.html',message=message)
else:
message = "login filed"
return render_template('index.html',message=message)
return render_template('index.html',message="weidenglu") @app.route('/register', methods=['POST','GET'])
def register():
if request.method == 'POST':
username = request.form.get('username')
password = request.form.get('password')
print (username)
addUser(username,password)
return ""
return render_template('index.html')
if __name__ == "__main__":
app.debug = True
app.run(port=7777)

html

 

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>{{ message }} index.html2</h1>
<h1>login</h1>
<form action="/login" method="POST">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="提交">
</form>
</body>
</html>

 

												

最新文章

  1. Vector Tile
  2. (2)RGB-D SLAM系列- 工具篇(依赖库及编译)
  3. [原创]java WEB学习笔记66:Struts2 学习之路--Struts的CRUD操作( 查看 / 删除/ 添加) 使用 paramsPrepareParamsStack 重构代码 ,PrepareInterceptor拦截器,paramsPrepareParamsStack 拦截器栈
  4. PHP多线程类
  5. jsp %EF%BB%BF
  6. iOS学习笔记之Category
  7. nyoj 119 士兵杀敌(三)(RMQ)
  8. 李洪强漫谈iOS开发[C语言-018]-scanf函数
  9. 由于java.util.Arrays.asList(...)导致的异常
  10. 4. sudo,PATH环境变量,修改字符集,ntpserver,加大文件描述符,隐藏内核版本,锁定关键系统文件
  11. 2013-9百度技术沙龙:Clouda与nodejs
  12. android studio 学习之一 安装和基本使用
  13. python自动化运维之路~DAY2
  14. Ubuntu 编译安装 nDPI
  15. iOS-UICollectionViewLayout方法介绍
  16. centos6编译安装zabbix3.0和中文支持整理文档
  17. Python入门1(简介、安装)
  18. 重命名IDEA14项目名
  19. Tomcat的HTTPS配置及HTTP自动跳转配置
  20. python教程(一)&#183;简介

热门文章

  1. python requests 包 使用
  2. php中的date和strtotime函数妙用
  3. 991 AlvinZH的奇幻猜想----整数乘积plus(背包DP大作战P)
  4. [转]IOS应用程序多语言本地化解决方案
  5. 【Python】二进制转ASCII码小脚本
  6. Shiro在SpringBoot中的使用
  7. Springboot集成WebSocket通信全部代码,即扣即用。
  8. numpy多维矩阵,取出第一行或者第一列,方法和df一样
  9. Html checkbox全选
  10. JUnit快速入门