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>

 

												

flask 简易注册登陆的更多相关文章

  1. form表单简易注册登陆

    注册页面: html <form action="updata.php" method="post" id="text_form"&g ...

  2. APP注册&登陆 逻辑细节

    前言:有多少用户愿意注册登陆,决定了一款产品的最大活跃度. 用户登陆注册系统分为两大类: 自建用户系统:邮箱/手机号/用户名/二维码/人脸识别/指纹 第三方授权用户系统:微信/微博/支付包/豆瓣/Fa ...

  3. 1_python小程序之实现用户的注册登陆验证功能

    python小程序之实现用户的注册登陆验证功能 程序扼要简述:  一.程序流程:1.程序开始2.判断本地文件/数据库是否已存在用户信息,存在则跳转到登陆,否则跳转到注册,注册成功后后跳转到登陆3.判断 ...

  4. Django项目:CRM(客户关系管理系统)--53--44PerfectCRM实现账号快速注册登陆

    # gbacc_ajax_urls.py # ————————42PerfectCRM实现AJAX全局账号注册———————— from django.conf.urls import url fro ...

  5. 用JDBC做账号注册登陆

    一.先用JDBC做账号登陆 方法一:用createStatement方法做账号登陆 测试结果:当输入正确账号密码时:当输入错误账号密码时: 当用注入攻击输入账号密码时: 注入攻击的原理是 输入任意值' ...

  6. python模拟---注册登陆查看个人信息

    需求:1.模拟注册: 2.模拟登陆: 3.模拟登陆成功显示登陆成功的用户账号: 一.注册 代码如下: def regetist(): ''' :param username: 注册的账号 :param ...

  7. jsp+servlet实现最基本的注册登陆功能

    源码和数据库下载地址:http://download.csdn.net/detail/biexiansheng/9759722 1:首先需要设计好数据库和数据表,这里简单截图说明我创建的字段和类型. ...

  8. flask登录注册简单的例子

    1.主程序 # app.py # Auther: hhh5460 # Time: 2018/10/05 # Address: DongGuan YueHua from functools import ...

  9. 【转载】Django自带的注册登陆功能

    1.登陆 知识点: a.auth.authenticate(username=name值, password=password值) 验证用户名和密码 b.auth.login(request, use ...

随机推荐

  1. Squid代理服务器(四)——反向代理

    一.概念 反向代理主要实现的是我们内部网站的加速功能 ,许多大型的门户网站架构中都采用了反向代理加速,使用比较多的是nginx.squid等,通过squid反向代理加速网站的访问速度,可将不同的url ...

  2. 【洛谷 5002】专心OI - 找祖先 (树上计数)

    专心OI - 找祖先 题目背景 \(Imakf\)是一个小蒟蒻,他最近刚学了\(LCA\),他在手机\(APP\)里看到一个游戏也叫做\(LCA\)就下载了下来. 题目描述 这个游戏会给出你一棵树,这 ...

  3. unicode 转换成中文

    unicode 转换成中文 + (NSString *)replaceUnicode:(NSString *)unicodeStr { NSString *tempStr1 = [unicodeStr ...

  4. git.exe 妙用

    1.如果 window 上的命令行,在进行编译的不好使 可以尝试在git 中运行 2.运行 python 脚本 ,保持脚本一直执行(尤其是中间出错) 可以做一个 sh 文件,然后在git 中运行 #! ...

  5. FPGA基础学习(7) -- 内部结构之CLB

    目录 1. 总览 2. 可配置逻辑单元 2.1 6输入查找表(LUT6) 2.2 选择器(MUX) 2.3 进位链(Carry Chain) 2.4 触发器(Flip-Flop) 参考文献: 一直以来 ...

  6. error C2955: “std::xx”: 使用 类 模板 需要 模板 参数列表

    一般出现这个错误 最可能是一种情况 queue q;//这样写 这样写肯定错 [笑哭] queue<int> q; //正确的 我想静静了

  7. telent三种认证及vlan简单划分

    实验一 telent三种认证方式登录 实验拓扑图如下: 操作过程: 1.认证模式为none R1操作:       1.system-view进入系统试图2.telnet server enable开 ...

  8. 1095. Maximum Swap —— Weekly Challenge

    题目限定输入是[0, 10^8],因而不用考虑负数或者越界情况,算是减小了难度. public class Solution { /** * @param num: a non-negative in ...

  9. STM32的GPIO工作原理 | 附电路图详细分析

    STM32的GPIO介绍 STM32引脚说明 GPIO是通用输入/输出端口的简称,是STM32可控制的引脚.GPIO的引脚与外部硬件设备连接,可实现与外部通讯.控制外部硬件或者采集外部硬件数据的功能. ...

  10. vue中nextTick的使用(转载)

    转载自:https://www.cnblogs.com/chaoyuehedy/p/8985425.html 简介 vue是非常流行的框架,他结合了angular和react的优点,从而形成了一个轻量 ...