START演示视频:

django新手

(登录 注册 增删查 已完成 简易)

一.登录功能、注册功能

1.没有注册账号,判断,提示该账户未注册,注册后写入数据库(mysql)
2.登录功能 --暂且提示登陆成功;空用户名提示、中文字符提示,不存在提示

登录模板层:


```python```python```html
<html>
<head><title>测试登录</title><style>form{width:100%;height:100%;margin-top: 0px;margin-bottom: 20px;background:#008B8B;}div{display:inline-block;padding-top: 255px;padding-bottom: 255px;padding-left: 1px;padding-right: 1px;}</style>
</head>
<body><center>
<form method="post" action="/login_action/"><h1>登录测试</h1><div>用户名:<input name="username", type="text"><br>密  码:<input name="password", type="password"><br>{{ error }}</br><button id="btn", type="submit">登录</button></div>{% csrf_token %}
</form>
</center></body></html>

url

urlpatterns = [path('admin/', admin.site.urls),path('index/', views.index),path('sign/', views.sign),path('login/', views.login),

视图层

def login(request):return render(request,'login.html',{'test':request.method})def login_action(request):if request.method =='POST':user = request.POST.get('username')password = request.POST.get('password')if len(user)== 0 or len(password)==0:# response = HttpResponseRedirect('/login_right/')# response.set_cookie('user', user, 3600)# request.session['user'] = user# return responsereturn render(request, 'login.html',{'error':'用户名密码不能为空'})else:for _char in user:if '\u4e00' <= _char <= '\u9fa5':return render(request, 'sign.html',{'error':'用户名不能包含中文字符'})user_list = models.Admin.objects.all()logger.debug('开始判断用户:{}{}'.format(user,password))for judge_user in user_list:if judge_user.user == user and judge_user.password == password:response = HttpResponseRedirect('/login_right/')response.set_cookie('user', user, 3600)models.Admin.objects.create(user = user,password=password)request.session['user'] = userreturn  responseelse:continue@login_required
def login_right(request):user =request.COOKIES.get('user','')# user =request.session.get('user','')return render(request,'login_action.html',{'user':user}

模型层

class Student(models.Model):"""创建如下几个表的字段"""# 学号 primary_key=True: 该字段为主键studentNum = models.CharField('学号', primary_key=True, max_length=15)# 姓名 字符串 最大长度20name = models.CharField('姓名', max_length=20)# 年龄 整数 null=False, 表示该字段不能为空age = models.IntegerField('年龄', null=False)# 性别 布尔类型 默认True: 男生 False:女生sex = models.BooleanField('性别', default=True)# 手机 unique=True 该字段唯一mobile = models.CharField('手机', unique=True, max_length=15)# 创建时间 auto_now_add:只有在新增的时候才会生效createTime = models.DateTimeField(auto_now_add=True)# 修改时间 auto_now: 添加和修改都会改变时间modifyTime = models.DateTimeField(auto_now=True)hobby = models.CharField(max_length=13,default="study")'''登录用户'''
class Admin(models.Model):user =models.CharField(max_length=20)password = models.CharField(max_length=20)

二.登录成功 跳转主页 校验失败 提示

主页

三.增删改查-查询学生信息

templates:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>For Students</title>
</head>
<style>* {margin: 0px;padding: 0px;}.top {height: 100px;background-color: #041858;color: honeydew;}.banner {height: 41px;background-color: #fcfcfc;text-align: right;line-height: 50px;border-top: 3px solid #ff8500;border-bottom: solid 1px #edeef0;}.bc {display: inline-block;width: 80px;height: 40px;font-size: 20px;color: #4c4c4c;line-height: 40px;padding: 0px 20px;text-decoration: none;}a.x {display: block;width: 140px;height: 70px;background-color: rgba(124, 119, 124, 0.993);text-decoration: none;text-align: center;color: cornsilk;line-height: 70px;}a.x:hover {background-color: yellowgreen;}</style>
<body><div class="header"><div class="top"><a style="text-decoration: none;line-height: 100px;font-family:STCaiyun; color: honeydew;font-size: 40px;" id="two">For Students</a></div><div class="banner"><a class="bc" href="/index">首页导航</a><a class="bc" href="yingxiaojieshao.html">学习园地</a><a class="bc" href="anli.html">在校实习</a><a class="bc" href="#">学生管理</a><a class="bc" href="#">其他板块</a><a class="bc" href="guanyu.html">关于网站</a></div></div><center>
<p>学生表信息</p><form action="/student_query" , method="get"><input name="student_query",type="text"><button id='btn',type="submit">查询</button><br>{% for item in msg %}{{ item.studentNum }}{{ item.name }} {{ item.age }}{%  endfor %}</form>
<table border="1"><tr><td>学号</td><td>姓名</td><td>年龄</td><td>电话</td><td>入学时间</td><td>上次修改</td><td>操作<a href="/student_add" > 添加</a></td></tr>{% for item in student_list %}<tr><td>{{ item.studentNum }}</td><td>{{ item.name }}</td><td>{{ item.age }}</td><td>{{ item.mobile }}</td><td>{{ item.createTime|date:"Y-m-d H:i:s" }}</td><td>{{ item.modifyTime|date:"Y-m-d H:i:s" }}</td><td><a href="student_add" > 修改</a><a href="/student_del/?studentNum={{ item.studentNum }}" > 删除</a></td></tr>{% endfor %}{{ msg}}</table></center>
</body>
</html>

views

def student_info(request):student_list =models.Student.objects.all()# models.Admin.objects.filter(user='zhaowenyao').delete()return  render(request,'student_info.html',{'student_list':student_list})

效果展示 点击 学生信息跳转

查询指定学生信息

views:

def student_query(request):if request.method == 'GET':studentNum =request.GET.get('student_query')data_list = models.Student.objects.filter(studentNum =studentNum)return render(request,'student_query.html',{'msg':data_list})

模板

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>For Students</title>
</head>
<style>* {margin: 0px;padding: 0px;}.top {height: 100px;background-color: #041858;color: honeydew;}.banner {height: 41px;background-color: #fcfcfc;text-align: right;line-height: 50px;border-top: 3px solid #ff8500;border-bottom: solid 1px #edeef0;}.bc {display: inline-block;width: 80px;height: 40px;font-size: 20px;color: #4c4c4c;line-height: 40px;padding: 0px 20px;text-decoration: none;}a.x {display: block;width: 140px;height: 70px;background-color: rgba(124, 119, 124, 0.993);text-decoration: none;text-align: center;color: cornsilk;line-height: 70px;}a.x:hover {background-color: yellowgreen;}</style>
<body><div class="header"><div class="top"><a style="text-decoration: none;line-height: 100px;font-family:STCaiyun; color: honeydew;font-size: 40px;" id="two">For Students</a></div><div class="banner"><a class="bc" href="/index">首页导航</a><a class="bc" href="yingxiaojieshao.html">学习园地</a><a class="bc" href="anli.html">在校实习</a><a class="bc" href="#">学生管理</a><a class="bc" href="#">其他板块</a><a class="bc" href="guanyu.html">关于网站</a></div></div><center>
<p>学生表信息</p><form action="/student_query" , method="get"><input name="student_query",type="text"><button id='btn',type="submit">查询</button> <a href="/student_info">返回</a><br></form>
<table border="1"><tr><td>学号</td><td>姓名</td><td>年龄</td></tr>{% for item in msg %}<tr><td>{{ item.studentNum }}</td><td>{{ item.name }}</td><td> {{ item.age }}</td></tr>{% endfor %}<br>{%if item.studentNum == None %}<p>学生信息不存在</p>{%endif%}</table></center>
</body>
</html>

删除学生信息

def student_del(request):if request.method == 'GET':studentNum = request.GET.get('studentNum')models.Student.objects.filter(studentNum=studentNum).delete()student_list = models.Student.objects.all()# models.Admin.objects.filter(user='zhaowenyao').delete()return render(request, 'student_info.html', {'student_list': student_list})

增加学生信息

views

def student_add(request):if request.method == 'GET':return render(request,'student_add.html')if request.method == 'POST':name = request.POST.get('name')no = request.POST.get('no')age = request.POST.get('age')mobile = request.POST.get('mobile')logger.debug('开始判断用户:{}{}'.format(name, no))if len(name) == 0 or len(no) == 0 or len(age)==0 or len(mobile)==0:return render(request, 'student_add.html', {'error': '不能为空'})else:for _char in name:if '\u4e00' <= _char <= '\u9fa5':return render(request, 'sign.html', {'error': '用户名不能包含中文字符'})models.Student.objects.create(studentNum=no, name=name, age=age, mobile=mobile)student_list = models.Student.objects.all()return   render(request, 'student_info.html', {'student_list':student_list,'msg': '添加成功'})

模板

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>学生管理系统</title>
</head>
<style>* {margin: 0px;padding: 0px;}.top {height: 100px;background-color: #041858;color: honeydew;}.banner {height: 41px;background-color: #fcfcfc;text-align: right;line-height: 50px;border-top: 3px solid #ff8500;border-bottom: solid 1px #edeef0;}.bc {display: inline-block;width: 80px;height: 40px;font-size: 20px;color: #4c4c4c;line-height: 40px;padding: 0px 20px;text-decoration: none;}a.x {display: block;width: 140px;height: 70px;background-color: rgba(124, 119, 124, 0.993);text-decoration: none;text-align: center;color: cornsilk;line-height: 70px;}a.x:hover {background-color: yellowgreen;}</style>
<body><div class="header"><div class="top"><a style="text-decoration: none;line-height: 100px;font-family:STCaiyun; color: honeydew;font-size: 40px;" id="two">学生管理系统</a></div><div class="banner"><a class="bc" href="http://127.0.0.1:8000/student_info.html">首页导航</a><a class="bc" href="yingxiaojieshao.html">学习园地</a><a class="bc" href="anli.html">在校实习</a><a class="bc" href="#">学生管理</a><a class="bc" href="#">其他板块</a><a class="bc" href="guanyu.html">关于网站</a></div></div>
<h2>添加学生表信息</h2>
<form method="post" action="/student_add/"><div>姓  名:<input name="name", type="text"><br>年  龄:<input name="age", type="text"><br>学  号:<input name="no", type="no"><br>电  话:<input name="mobile", type="mobile"><br><button id="btn", type="submit">添加</button>{% csrf_token %}</div>
</form>
</body>
</html>

Django--学生管理系统(django慢更)相关推荐

  1. 学生管理系统——Django

    目录 前言 一.Django是什么? 二.使用步骤 1.创建Django项目 (1)mkdir Django (2) cd MyDjango\dir ​(3)文件夹显示 (4)进入pyCharm界面 ...

  2. Python django 会议室管理系统

    Python django 会议室管理系统 django会议室申请系统 django会议室系统 技术:Python django 数据库:MySQL 涉及功能:登录.注册.登出.管理员登录.管理用户信 ...

  3. python学生管理系统-学生管理系统python

    广告关闭 腾讯云+校园是针对学生用户推出的专项扶持计划,1核2G云服务器9元/月起,云数据库2元/月起,并享受按购买价续费的优惠,助力莘莘学子轻松上云 print(该学生不存在)return none ...

  4. 学生管理系统(链表)

    文章目录 前言 一.具体过程 1.引入头文件contact.h 2.创建test.c 3.创建contact.c 二.写在最后 前言 链表的学生管理系统相比之前更高效,同样有内存的扩充,也补充了文件操 ...

  5. Django实训-学生管理系统

    文章目录 项目总述 1,功能分析 增加学生记录,查询学生记录,修改学生记录,删除学生记录 2,需求分析 可以查询个人学生信息,包括根据学号查询学习基本情况和选课信息 可以更省时间的查询信息 一.创建D ...

  6. python基于django学生成绩管理系统o8mkp

    目录 1 绪论 1 1.1课题背景 1 1.2课题研究现状 1 1.3初步设计方法与实施方案 2 1.4本文研究内容 2 2 系统开发环境 4 2.1 django简介 4  2.3 B/S结构简介 ...

  7. Django作业管理系统(1)

    Django作业管理系统1-需求分析报告 一.引言 1.编写目的 2.项目背景 3.术语定义: 二.综合描述 1.产品介绍 2.目标范围 3.用户特性 4.约定假设 三.功能需求 业务需求功能模型-- ...

  8. 基于python-实训基地管理系统-django框架计算机毕业设计源码+系统+数据库+lw文档+调试部署

    基于python-实训基地管理系统-django框架计算机毕业设计源码+系统+数据库+lw文档+调试部署 基于python-实训基地管理系统-django框架计算机毕业设计源码+系统+数据库+lw文档 ...

  9. 基于python食品安全溯源管理系统django框架计算机毕业设计源码+系统+数据库+lw文档+调试部署

    基于python食品安全溯源管理系统django框架计算机毕业设计源码+系统+数据库+lw文档+调试部署 基于python食品安全溯源管理系统django框架计算机毕业设计源码+系统+数据库+lw文档 ...

  10. django后台管理系统

    文章目录 一.django基本操作 二.打开项目 数据库迁移 一.django基本操作 django后台管理系统基本操作 Django配合python的使用可以说是非常友好帮助我们搭建后台管理,包括良 ...

最新文章

  1. linux无文件渗透执行elf
  2. C 线程池(不稳定的方案)
  3. mysql数据库密码为空_注意MySQL数据库用户root密码为空
  4. 有一说一,确实。。 | 今日最佳
  5. 编程语言分类 -- 强类型与弱类型、动态类型与静态类型
  6. 红橙Darren视频笔记 builder设计模式+navigationBar导航条
  7. 纠正Pandas中的缺失数据
  8. zw版【转发·台湾nvp系列Delphi例程】.NET调用HALCON COM控件内存释放模式
  9. Web安全之SQL注入攻击技巧与防范
  10. node2vec文献出处_图表示学习入门2——Node2Vec
  11. C#窗体之整人小程序
  12. 风格迁移应用_图像风格迁移
  13. hyperledger fabric 测试(九)couch DB数据库设置
  14. 想要吸引女性粉丝?三种短视频类型可尝试,点赞关注少不了
  15. 使用phpQuery采集图片示例–php采集方式之一
  16. textarea标签 禁止拉伸
  17. Couldn‘t store trigger ‘‘ for ‘‘ job:Couldn‘t retrieve job because the BLOB couldn‘t be deserialized
  18. 如何找国外作者的matlab,如何与外国学者用电子邮件联系(索要论文或者代码)...
  19. 字节跳动(上海抖音)面经
  20. 获取一个新的日期,它的值为指定日期当年的最后一天

热门文章

  1. 无限极分类在html怎么用,wxj.html
  2. Microsoft Dynamics CRM 常用JS语法(已转成vs2017语法提示)
  3. [iOS]高德地图SDK开发--准备篇
  4. 小米路由器 建mysql_轻松在小米路由建自己的网站
  5. Mac装机必备软件2020最全下载集合
  6. 软件测试团队口号及队名,霸气响亮的队名和口号押韵 有创意的团队口号
  7. 用python写一个解一元二次方程的类
  8. WATCH ME 2007
  9. 关于调用第三方sdk
  10. kindle看pdf的文档字体调小了