最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2019年02月26日 10:10:58   作者:yaoliuwei1426  
這篇文章主要為大家詳細(xì)介紹了Django實(shí)現(xiàn)學(xué)生管理系統(tǒng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

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

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

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

views.py

from django.shortcuts import render,reverse
from stusys import models
from 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 admin
from django.urls import path
from stusys import views
urlpatterns = [
  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>學(xué)生成績(jī)管理系統(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" >首頁(yè)</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>

add.html

{% extends 'base.html' %}
{% block content %}
  <div>
    <form action ="{% url 'add_stuinfo' %}" method="post">
    {% csrf_token %}
      <table class="table" style="border-style:none;width: 50%" >
        <tr>
          <td style="border-style:none" >學(xué)  號(hào):</td>
          <td style="border-style:none"><input name="id"></td>
        </tr>
        <tr>
          <td style="border-style:none">姓  名:</td>
          <td style="border-style:none"><input name="name"></td>
        </tr>
        <tr>
          <td style="border-style:none">數(shù)學(xué)成績(jī):</td>
          <td style="border-style:none"><input name="math"></td>
        </tr>
        <tr>
          <td style="border-style:none">語(yǔ)文成績(jī):</td>
          <td style="border-style:none"><input name="chinese"></td>
        </tr>
        <tr>
          <td style="border-style:none">英語(yǔ)成績(jī):</td>
          <td style="border-style:none"><input name="english"></td>
        </tr>
        <tr>
          <td colspan="2" style="border-style:none" ><input type="submit" value="添加" style="width:100px;height:40px;"></td>
        </tr>
      </table>
    </form>
  </div>
 
{% endblock %}

info.html

{% extends 'base.html' %}
{% block content %}
  <table class="table" >
  <thead>
    <tr >
      <td >學(xué)號(hào)</td>
      <td >姓名</td>
      <td >數(shù)學(xué)</td>
      <td >語(yǔ)文</td>
      <td >英文</td>
      <td >總分</td>
      <td colspan="2">  </td>
    </tr>
  </thead>
     <tbody>
      {% for stuinfo in stuinfo_list %}
        <tr >
          <td >{{ stuinfo.id }}</td>
          <td >{{ stuinfo.name }}</td>
          <td >{{ stuinfo.math}}</td>
          <td >{{ stuinfo.chinese }}</td>
          <td >{{ stuinfo.english }}</td>
          <td >{{ stuinfo.total }}</td>
          <td ><a href="{% url 'del_stuinfo' %}?id={{ stuinfo.id}}" rel="external nofollow" >刪除</a></td>
          <td ><a href="{% url 'mod_stuinfo' %}?id={{ stuinfo.id}}" rel="external nofollow" >修改</a></td>
        </tr>
      {% endfor %}
     </tbody>
  </table>
{% endblock %}

mod.html

{% extends 'base.html' %}
{% block content %}
{#    <form action ="{% url 'mod_stuinfo' %}" method="post">#}
{#    {% csrf_token %}#}
{#      #}
{#    <p>學(xué)  號(hào):<input name="id" type="text" value="{{ stu_detail.id}}" readonly="readonly" ></p>#}
{#    <p>姓  名:<input name="name" type="text" value="{{ stu_detail.name}}"></p>#}
{#    <p>數(shù)學(xué)成績(jī):<input name="math" type="text" value="{{ stu_detail.math}}"></p>#}
{#    <p>語(yǔ)文成績(jī):<input name="chinese" type="text" value="{{ stu_detail.chinese}}"></p>#}
{#    <p>英語(yǔ)成績(jī):<input name="english" type="text" value="{{ stu_detail.english}}"></p>#}
{#    <p><input type="submit" value="修改"></p>#}
{#    </form>#}
    <form action ="{% url 'mod_stuinfo' %}" method="post">
    {% csrf_token %}
      <table class="table" style="border-style:none;width: 50%" >
        <tr>
          <td style="border-style:none" >學(xué)  號(hào):</td>
          <td style="border-style:none"><input name="id" type="text" value="{{ stu_detail.id}}" readonly="readonly" disabled="disabled"></td>
        </tr>
        <tr>
          <td style="border-style:none">姓  名:</td>
          <td style="border-style:none"><input name="name" type="text" value="{{ stu_detail.name}}"></td>
        </tr>
        <tr>
          <td style="border-style:none">數(shù)學(xué)成績(jī):</td>
          <td style="border-style:none"><input name="math" type="text" value="{{ stu_detail.math}}"></td>
        </tr>
        <tr>
          <td style="border-style:none">語(yǔ)文成績(jī):</td>
          <td style="border-style:none"><input name="chinese" type="text" value="{{ stu_detail.chinese}}"></td>
        </tr>
        <tr>
          <td style="border-style:none">英語(yǔ)成績(jī):</td>
          <td style="border-style:none"><input name="english" type="text" value="{{ stu_detail.english}}"></td>
        </tr>
        <tr>
          <td colspan="2" style="border-style:none" ><input type="submit" value="修改" style="width:100px;height:40px;"></td>
        </tr>
      </table>
    </form>
{% endblock %}

靜態(tài)資源文件:

nav.css

*{
  margin: 0;
  padding: 0;
}
 
.nav{
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333;
  position: fixed;
  top: 0;
  width: 100%;
}
 
.nav li{
  float: left;
}
 
.nav li a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}
 
.nav li a:hover:not(.active) {
  background-color: #111;
}
 
.active {
  background-color: #4CAF50;
} 

table.css

.table{
  margin-top:50px;width:100% ;border:solid #add9c0; border-width:1px 0px 0px 1px;}
 
.table tr td {
  border:solid #add9c0; border-width:0px 1px 1px 0px; padding:10px 0px;font-size:18px;align:center;}
 
.table tr td input{
  width: 250px; height: 30px;font-size:18px
}

實(shí)現(xiàn)效果如下:

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

相關(guān)文章

  • Python中遇到的小問(wèn)題及解決方法匯總

    Python中遇到的小問(wèn)題及解決方法匯總

    到年底了,現(xiàn)在的時(shí)間適合寫點(diǎn)最近的小總結(jié),所以下面這篇文章主要介紹了Python中遇到的一些小問(wèn)題及解決方法,需要的朋友可以參考借鑒,下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-01-01
  • pytorch報(bào)錯(cuò)問(wèn)題:ValueError: num_samples should be a positive integer value, but got num_samples=0

    pytorch報(bào)錯(cuò)問(wèn)題:ValueError: num_samples should be

    這篇文章主要介紹了pytorch報(bào)錯(cuò)問(wèn)題:ValueError: num_samples should be a positive integer value, but got num_samples=0的解決方案,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • 關(guān)于DataFrame中某列值的替換map(dict)

    關(guān)于DataFrame中某列值的替換map(dict)

    這篇文章主要介紹了關(guān)于DataFrame中某列值的替換map(dict),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • Python按天實(shí)現(xiàn)生成時(shí)間范圍序列的方法詳解

    Python按天實(shí)現(xiàn)生成時(shí)間范圍序列的方法詳解

    有的時(shí)候我們希望生成一段時(shí)間返回,比如從?2022-01-01?00:00:00?后面的?10?天,這么?10?個(gè)?datetime?對(duì)象,但是我們又不想自己去計(jì)算哪些月有30天哪些月有31天。所以本文將用Python實(shí)現(xiàn)按天自動(dòng)生成時(shí)間范圍序列,需要的可以參考一下
    2022-11-11
  • numpy拼接矩陣的實(shí)現(xiàn)

    numpy拼接矩陣的實(shí)現(xiàn)

    本文主要介紹了numpy拼接矩陣的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • Python OS系統(tǒng)解決路徑中空格原因?qū)е挛募虿婚_的問(wèn)題

    Python OS系統(tǒng)解決路徑中空格原因?qū)е挛募虿婚_的問(wèn)題

    這篇文章主要介紹了Python OS系統(tǒng)解決路徑中空格原因?qū)е挛募虿婚_的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • python使用pika庫(kù)調(diào)用rabbitmq參數(shù)使用詳情

    python使用pika庫(kù)調(diào)用rabbitmq參數(shù)使用詳情

    這篇文章主要介紹了python使用pika庫(kù)調(diào)用rabbitmq參數(shù)使用詳情,文章通過(guò)展開文章主題分享了三種方式,具有一定的參考價(jià)值,需要的朋友可以參考一下
    2022-08-08
  • python如何導(dǎo)出微信公眾號(hào)文章方法詳解

    python如何導(dǎo)出微信公眾號(hào)文章方法詳解

    這篇文章主要介紹了python如何導(dǎo)出微信公眾號(hào)文章方法詳解,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • 利用OpenCV實(shí)現(xiàn)質(zhì)心跟蹤算法

    利用OpenCV實(shí)現(xiàn)質(zhì)心跟蹤算法

    質(zhì)心跟蹤算法不是正統(tǒng)的目標(biāo)跟蹤,而是在多目標(biāo)跟蹤中結(jié)合目標(biāo)檢測(cè)算法不同幀之間的相同目標(biāo)做一個(gè)link。本文將利用OpenCV實(shí)現(xiàn)質(zhì)心跟蹤算法,感興趣的可以試一試
    2022-01-01
  • Python實(shí)現(xiàn)兩種多分類混淆矩陣

    Python實(shí)現(xiàn)兩種多分類混淆矩陣

    這篇文章主要為大家介紹了Python實(shí)現(xiàn)兩種多分類混淆矩陣,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-06-06

最新評(píng)論

历史| 耒阳市| 营口市| 个旧市| 新巴尔虎右旗| 信宜市| 随州市| 广水市| 溧阳市| 乾安县| 鞍山市| 隆子县| 邯郸县| 吉首市| 玉环县| 胶州市| 五指山市| 南安市| 瑞安市| 东乡族自治县| 太仓市| 南汇区| 林甸县| 武乡县| 淳安县| 南安市| 鹿泉市| 手机| 淳化县| 宜宾县| 托克托县| 山西省| 屯昌县| 玉屏| 民和| 朔州市| 涿州市| 原平市| 龙游县| 理塘县| 诸暨市|