国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Django實現(xiàn)學生管理系統(tǒng)

2020-02-16 01:21:48
字體:
供稿:網(wǎng)友

Django學習筆記-學生管理系統(tǒng)(Django實現(xiàn))筆記中僅實現(xiàn)了對數(shù)據(jù)的全部查詢。

下面實現(xiàn)新增、刪除、修改,代碼如下。

下面的代碼沒有對輸入框內(nèi)容進行限制,如果輸入不符合規(guī)則的內(nèi)容,會出現(xiàn)錯誤。

本篇更新完畢后Django更新暫停一段,由于工作崗位是測試工程師,后面將重點關(guān)注測試相關(guān)內(nèi)容。

views.py

from django.shortcuts import render,reversefrom stusys import modelsfrom django.http import HttpResponseRedirect def stuinfo(request):  stuinfo_list_obj = models.Stuinfo.objects.all()  return render(request,'info.html',{'stuinfo_list':stuinfo_list_obj})def add_stuinfo(request):  if request.method == "POST":    id = request.POST['id']    name = request.POST['name']    math = request.POST['math']    chinese=request.POST['chinese']    english=request.POST['english']    total=float(math)+float(chinese)+float(english)    models.Stuinfo.objects.create(id=id,name=name,math=math,chinese=chinese,english=english,total=total)    return HttpResponseRedirect(reverse('stuinfo'))  elif request.method == "GET":    return render(request,'add.html') def del_stuinfo(request):  id=request.GET.get('id')  models.Stuinfo.objects.filter(id=id).delete()  return HttpResponseRedirect(reverse('stuinfo')) def mod_stuinfo(request):  if request.method=='GET':    id = request.GET.get('id')    stu_detail =models.Stuinfo.objects.get(id=id)    context={'stu_detail':stu_detail}    return render(request,'mod.html',context=context)  if request.method=="POST":    id = request.POST['id']    name = request.POST['name']    math = request.POST['math']    chinese=request.POST['chinese']    english=request.POST['english']    total=float(math)+float(chinese)+float(english)    models.Stuinfo.objects.filter(id=id).update(name=name,math=math,chinese=chinese,english=english,total=total)    return HttpResponseRedirect(reverse('stuinfo'))

urls.py

from django.contrib import adminfrom django.urls import pathfrom stusys import viewsurlpatterns = [  path('admin/', admin.site.urls),  path('',views.stuinfo,name='stuinfo'),  path('add/',views.add_stuinfo,name='add_stuinfo'),  path('del/',views.del_stuinfo,name='del_stuinfo'),  path('mod/',views.mod_stuinfo,name='mod_stuinfo')]

templates

base.html

{% load static %}<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title>學生成績管理系統(tǒng)</title>  <link rel="stylesheet" href="{% static 'nav.css' %}" rel="external nofollow" >  <link rel="stylesheet" href="{% static 'table.css' %}" rel="external nofollow" ></head><body>   <ul class="nav">        <li><a href="{% url 'stuinfo' %} " rel="external nofollow" >首頁</a></li>        <li><a href="{% url 'add_stuinfo' %} " rel="external nofollow" >添加</a></li>  </ul>  <div style="padding:20px;margin-top:30px;background-color:#1abc9c;height:1500px;">    {% block content %} {% endblock %}  </div> </body></html>            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 门头沟区| 广东省| 开封市| 剑川县| 南安市| 凉山| 秦皇岛市| 绥芬河市| 新兴县| 公主岭市| 沾益县| 恩施市| 凌海市| 拉孜县| 曲麻莱县| 虞城县| 保亭| 肥西县| 双流县| 平阴县| 新安县| 桦川县| 定结县| 湾仔区| 五河县| 桃园市| 科尔| 自治县| 沙雅县| 类乌齐县| 宝应县| 九台市| 泽库县| 老河口市| 铜山县| 榆林市| 房产| 买车| 屏山县| 团风县| 韶山市|