python+django+sql学生信息管理后台开发
作者:DW_Deven 时间:2021-10-09 11:20:26
一、功能
实现对学生对个人信息的增删查改
实现后台对所有学生信息的操作
二、平台
windows+pycharm(python开发工具)
三、逻辑框图
四、代码展示
此后台采用的是MVC的风格模式进行编码
1.VIEWS部分
def hello(request):#功能选择
# t = loader.get_template("hello.html")
# c = RequestContext(request)
return render_to_response("hello.html",context_instance=RequestContext(request))
def addstu(request):# 添加学生信息
name = request.POST.get("name")
age = request.POST.get("age")
learn = request.POST.get("learn")
newstu = Student(name=name,age=age,learn=learn)
newstu.save()
# c = RequestContext(request)
# t = loader.get_template("check.html")
return render_to_response("done.html",context_instance=RequestContext(request,{"age":age,"learn":learn,"name":name}))
def checkstu(request):#查询学生信息
find = []
stulist = Student.objects.all()
name = request.POST.get("name")
age = request.POST.get("age")
learn = request.POST.get("learn")
if name:
find = Student.objects.filter(name__contains=name)
elif age:
find = Student.objects.filter(age=age)
elif age:
find = Student.objects.filter(learn__contains=learn)
return render_to_response("check.html",context_instance=RequestContext(request,{"stulist":stulist,"find":find}))
def putmessage(request):#信息提交中转
return render_to_response("add.html",context_instance=RequestContext(request))
def deletStu(request):#删除学生信息
alert=""
name = request.POST.get("name")
age = request.POST.get("age")
learn = request.POST.get("learn")
delet = request.POST.get("delet")
find = Student.objects.filter(name__contains =name)
if not find:
alert = u"没有找到名为" + name + u"的学生"
elif not delet:
elert=""
else:
find.delete()
alert = u"成功删除该学生"
return render_to_response("delet.html",context_instance=RequestContext(request,{"alert":alert,"student":find}))
def putmessage2(request):#信息提交中转2
return render_to_response("put2.html",context_instance=RequestContext(request))
def rewrite(request):#学生信息更改
aler=u"提示:"
stulist = Student.objects.all()
message = request.POST.get("message")
old = request.POST.get("old")
new = request.POST.get("new")
if old == "name":
student= Student.objects.filter( name__contains = message).update(name = new)
aler+=u"信息修改成功"
elif old== "age":
student= Student.objects.filter( name__contains = message).update(age = new)
aler+=u"信息修改成功"
elif old =="learn":
student= Student.objects.filter( name__contains = message).update(learn = new)
aler+=u"信息修改成功"
else:
aler+=u"请输入正确的需要修改的信息类别(name,age或learn)"
return render_to_response("show.html",context_instance=RequestContext(request,{"id":id,"message":message,"new":new,"stulist":stulist,"aler":aler}))
2.MODELS 部分
class Student(models.Model):#学生模板
name = models.CharField(max_length=20)
age = models.IntegerField()
learn = models.CharField(max_length=20)
def __unicode__(self):
return self.name
class Teacher(models.Model):#老师模板
name = models.CharField(max_length=20)
age = models.IntegerField()
teach = models.CharField(max_length=20)
student = models.ManyToManyField( Student,through = "OneClass")
def __unicode__(self):
return self.name
class OneClass(models.Model):#班级模板
name = models.CharField(max_length=50)
teacher = models.ForeignKey(Teacher)
student = models.ForeignKey(Student)
def __unicode__(self):
return self.name
3.CONTROLLER部分
URL配置
urlpatterns = [url(r'^blog/','blog.views.hello'),
url(r'^adstu/','blog.views.addstu'),
url(r'^add/','blog.views.putmessage'),
url(r'^check/','blog.views.checkstu'),
url(r'^readydel/','blog.views.putmessage2'),
url(r'^delet/','blog.views.deletStu'),
url(r'^show/','blog.views.rewrite'),
url(r'^admin/', include(admin.site.urls)),]
表单的设置
__author__ = 'deven'
from django import forms
class ContentForm(forms.Form):
username = forms.CharField()#max_length = 20)
password = forms.IntegerField()#max_value= 20)
五、功能展示
1.主界面(功能选择)
2.增加学生信息
3.查询学生信息
4.删除学生信息
5.更改学生信息
来源:http://blog.csdn.net/dw_deven/article/details/48710167
标签:python,管理后台
0
投稿
猜你喜欢
Windows10下安装配置 perl 环境的详细教程
2022-11-17 01:46:32
Django+Ajax异步刷新/定时自动刷新实例详解
2023-11-29 11:28:15
Python 从attribute到property详解
2022-03-15 18:52:40
js判断复选框是否选中及选中个数的实现代码
2024-04-22 22:17:03
开心网上input输入框研究
2009-03-06 12:52:00
python保存图片的四个常用方法
2023-10-03 15:06:37
代码总结Python2 和 Python3 字符串的区别
2023-05-25 00:58:52
python使用梯度下降和牛顿法寻找Rosenbrock函数最小值实例
2022-09-10 20:01:20
Python面向对象之多态原理与用法案例分析
2023-08-16 00:09:59
Golang-如何判断一个 interface{} 的值是否为 nil
2024-02-17 10:08:10
Python中装饰器高级用法详解
2023-09-30 09:46:42
python多线程socket编程之多客户端接入
2021-01-26 10:14:52
简单谈谈GET和POST有什么区别
2022-06-06 04:53:41
浅谈javascript的分号[译]
2009-12-13 10:34:00
MySQL常用维护管理工具
2009-03-08 16:51:00
vue-router传参的4种方式超详细讲解
2024-04-27 15:48:21
python 虚拟环境的创建与使用方法
2022-11-09 18:21:50
python pyhs2 的安装操作
2021-03-11 18:21:33
python中几种自动微分库解析
2022-12-20 18:24:02
MAC下mysql安装配置方法图文教程
2024-01-17 22:38:46