服务器之家

服务器之家 > 正文

python+django+sql学生信息管理后台开发

时间:2021-01-04 00:15     来源/作者:DW_Deven

一、功能

实现对学生对个人信息的增删查改
实现后台对所有学生信息的操作

二、平台

windows+pycharm(python开发工具)

三、逻辑框图

四、代码展示

此后台采用的是MVC的风格模式进行编码

1.VIEWS部分

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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 部分

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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配置

?
1
2
3
4
5
6
7
8
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)),]

表单的设置

?
1
2
3
4
5
__author__ = 'deven'
from django import forms
class ContentForm(forms.Form):
 username = forms.CharField()#max_length = 20)
 password = forms.IntegerField()#max_value= 20)

五、功能展示

1.主界面(功能选择)

python+django+sql学生信息管理后台开发

2.增加学生信息

python+django+sql学生信息管理后台开发

3.查询学生信息

python+django+sql学生信息管理后台开发

4.删除学生信息

python+django+sql学生信息管理后台开发 python+django+sql学生信息管理后台开发

5.更改学生信息

python+django+sql学生信息管理后台开发python+django+sql学生信息管理后台开发

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:http://blog.csdn.net/dw_deven/article/details/48710167

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
电视剧《琉璃》全集在线观看 琉璃美人煞1-59集免费观看地址
电视剧《琉璃》全集在线观看 琉璃美人煞1-59集免费观看地址 2020-08-12
返回顶部