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. macdown快速上手

    1.断句 在结尾处输入两个空格并使用回车. 2.标题分级 使用#来进行分级,#越多级数越低 3.链接 可以使用<>里面直接加上地址 或者使用[}里面加上链接名字然后后面接上()里面就是地址 ...

  2. Bootrap 项目实战(微金所前端首页)第二部分(首页源码)

    首页源码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  3. Springboot第三篇:与前端fetch通信(关于前端传输json数据上传文件等等前后端的处理)

    关于前端接口传递的方法,推荐按以下使用: 若要在服务器上创建资源,推荐使用POST方法 若要检索某个资源,推荐使用GET方法 若要更新资源,推荐使用PUT方法 若要删除某个资源,推荐使用DELETE方 ...

  4. python学习,day3: 文件的读写

    # coding=utf-8 # Author: RyAn Bi import sys f1 = open('yesterday2',mode='w',encoding='utf-8') #w 只能写 ...

  5. [转] vagrant系列(2):使用Vagrantfile实现集成预安装

    在我们的开发目录下,有一个文件Vagrantfile,里面包含有大量的配置信息,主要包括三个方面:虚拟机配置.SSH配置.基础配置.Vagrant是使用Ruby开发的,所以它的配置语法也是Ruby的, ...

  6. FileZilla上傳報錯:421 There are too many connections from your internet address

    起因:2019年01月27日晚九點左右,想要將一個50MB+的文件夾上傳到阿里雲的虛擬主機上,使用FTP 工具FileZilla,出現了上傳一段時間後提示421 There are too many ...

  7. zabbix4.2 安装

    官网https://www.zabbix.com/cn/download a. 安装 数据库rpm -Uvh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86 ...

  8. tomcat各文件夹及作用

    1.bin目录:这个文件夹包含的是启动/关闭tomcat的脚本 2.conf目录:主要是用来存放一些Tomcat的配置文件,都是一些.xml部署文件,其中重要的有: server.xml:是Tomca ...

  9. Objective-C中.h、.m、.mm的区别

    .h :头文件.头文件包含类,类型,函数和常数的声明.  .m :源代码文件.这是典型的源代码文件扩展名,可以包含Objective-C和C代码.  .mm :源代码文件.带有这种扩展名的源代码文件, ...

  10. Mybatis基本介绍

    Mybatis介绍 1.Mybatis介绍   MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了goog ...