溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

python+django+sql學(xué)生信息管理后臺(tái)開(kāi)發(fā)

發(fā)布時(shí)間:2020-09-04 17:24:52 來(lái)源:腳本之家 閱讀:138 作者:DW_Deven 欄目:開(kāi)發(fā)技術(shù)

一、功能

實(shí)現(xiàn)對(duì)學(xué)生對(duì)個(gè)人信息的增刪查改
實(shí)現(xiàn)后臺(tái)對(duì)所有學(xué)生信息的操作

二、平臺(tái)

windows+pycharm(python開(kāi)發(fā)工具)

三、邏輯框圖

四、代碼展示

此后臺(tái)采用的是MVC的風(fēng)格模式進(jìn)行編碼

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):# 添加學(xué)生信息
 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):#查詢學(xué)生信息
 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):#信息提交中轉(zhuǎn)
 return render_to_response("add.html",context_instance=RequestContext(request))

def deletStu(request):#刪除學(xué)生信息
 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"沒(méi)有找到名為" + name + u"的學(xué)生"
 elif not delet:
  elert=""
 else:
  find.delete()
  alert = u"成功刪除該學(xué)生"
 return render_to_response("delet.html",context_instance=RequestContext(request,{"alert":alert,"student":find}))

def putmessage2(request):#信息提交中轉(zhuǎn)2
 return render_to_response("put2.html",context_instance=RequestContext(request))


def rewrite(request):#學(xué)生信息更改
 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"請(qǐng)輸入正確的需要修改的信息類別(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):#學(xué)生模板
 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):#班級(jí)模板
 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)),]

表單的設(shè)置

__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學(xué)生信息管理后臺(tái)開(kāi)發(fā)

2.增加學(xué)生信息

python+django+sql學(xué)生信息管理后臺(tái)開(kāi)發(fā)

3.查詢學(xué)生信息

python+django+sql學(xué)生信息管理后臺(tái)開(kāi)發(fā)

4.刪除學(xué)生信息

python+django+sql學(xué)生信息管理后臺(tái)開(kāi)發(fā) python+django+sql學(xué)生信息管理后臺(tái)開(kāi)發(fā)

5.更改學(xué)生信息

python+django+sql學(xué)生信息管理后臺(tái)開(kāi)發(fā)python+django+sql學(xué)生信息管理后臺(tái)開(kāi)發(fā)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI