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. C#-函数的传值与传址

    传值就是将实参的值传到所调用的函数里面,实参的值并没有发生变化,默认传值的有int型,浮点型,bool型,char字符型,结构体等等. 传址就是将地址传到所调用的函数里面操作,实参的值也会跟着变化,传 ...

  2. 关于window.open在不同浏览器的不同点

    菜鸟教程: http://www.runoob.com/jsref/met-win-open.html 一.基本语法:window.open(URL,name,specs,replace)其中:URL ...

  3. centos的 / ~ - 的意思

    . 当前目录 .. 上一层目录 - 前一个工作目录,上一次操作的目录 cd - 会切换都上次你操作的目录 ~ 当前[用户]所在的家目录/ root的根目录

  4. 洛谷 P3204 [HNOI2010]公交线路

    题面 luogu 题解 矩阵快速幂\(+dp\) 其实也不是很难 先考虑朴素状压\(dp\) \(f[i][S]\) 表示最慢的车走到了\(i\),\([i, p+i-1]\)的覆盖情况 状态第一位一 ...

  5. springcloud(三)-Eureka

    Eureka是Netflix开源的一款提供服务注册和发现的产品,它提供了完整的Service Registry和Service Discovery实现.也是springcloud体系中最重要最核心的组 ...

  6. Q438 找到字符串中所有字母异位词

    给定一个字符串 s 和一个非空字符串 p,找到 s 中所有是 p 的字母异位词的子串,返回这些子串的起始索引. 字符串只包含小写英文字母,并且字符串 s 和 p 的长度都不超过 20100. 说明: ...

  7. 使用Session监听器实现统计在线人数

    使用Session监听器实现统计在线人数 1.工作目录结构 包含监听器类和jsp页面 2.session监听器 首先利用session监听器来实现对访问网站时的session计数,当有session创 ...

  8. git特殊用法

    git stash的使用 1.当前分支写了一半的代码,需要切到其他分支修复bug或者完成优先级较高的任务时 git stash 暂存分支进度 git stash list 查看草稿区 git stas ...

  9. python小游戏开发关于pygame库的安装

    ---恢复内容开始--- 测试环境:运行环境 Window 10 64bit上运行 前提条件 python3.7(当前时间最新版本20181021)安装(记住安装路径如C:\application\p ...

  10. 解决重装 Oracle 出现的 INS-32025 问题,完全卸载 Oracle11g

    如果您要重装 Oracle,并且安装程序正在运行,请先关闭它. 完全卸载: 1.停止所有 Oracle 服务 2.通过开始菜单 Oracle Installation Products -> U ...