├── db.sqlite3
├── StudentInfo
├── __init__.py
├── migrations
│ └── __init__.py
├── tests.py
├── admin.py
├── apps.py
├── models.py
└── views.py
├── static
├── js
│ └── common.js
└── css
│ └── common.css
├── StudentInfoWebApp
├── __init__.py
├── wsgi.py
├── urls.py
└── settings.py
├── README.md
├── .idea
├── vcs.xml
├── modules.xml
├── misc.xml
└── StudentInfoWebApp.iml
├── manage.py
└── templates
├── index.html
├── add.html
├── delete.html
├── update.html
└── query.html
/db.sqlite3:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/StudentInfo/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/static/js/common.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/StudentInfo/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/StudentInfoWebApp/__init__.py:
--------------------------------------------------------------------------------
1 | import pymysql
2 |
3 | pymysql.install_as_MySQLdb()
4 |
--------------------------------------------------------------------------------
/StudentInfo/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/StudentInfo/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 |
3 | # Register your models here.
4 |
--------------------------------------------------------------------------------
/StudentInfo/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class StudentinfoConfig(AppConfig):
5 | name = 'StudentInfo'
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # StudentInfoWebApp
2 | 基于python的django框架写的学生信息管理系统
3 |
4 | 使用python3.6 + MySql5.7 + django 开发的一个demo。
5 | 主要的功能是学生信息的增删查找,界面功能比较简单,适合django初学者学习。
6 |
7 | 有疑问联系QQ: 1369990551
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/StudentInfoWebApp/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for StudentInfoWebApp project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "StudentInfoWebApp.settings")
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import os
3 | import sys
4 |
5 | if __name__ == "__main__":
6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "StudentInfoWebApp.settings")
7 | try:
8 | from django.core.management import execute_from_command_line
9 | except ImportError as exc:
10 | raise ImportError(
11 | "Couldn't import Django. Are you sure it's installed and "
12 | "available on your PYTHONPATH environment variable? Did you "
13 | "forget to activate a virtual environment?"
14 | ) from exc
15 | execute_from_command_line(sys.argv)
16 |
--------------------------------------------------------------------------------
/StudentInfo/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 |
4 | # Create your models here.
5 | # 学生类模板
6 | class Student(models.Model):
7 | name = models.CharField(max_length=20)
8 | age = models.IntegerField()
9 | learn = models.CharField(max_length=20)
10 |
11 |
12 | # 教师类模板
13 | class Teacher(models.Model):
14 | name = models.CharField(max_length=20)
15 | age = models.IntegerField()
16 | teach = models.CharField(max_length=20)
17 | student = models.ManyToManyField(Student, through="OneClass")
18 |
19 |
20 | # 班级类模板
21 | class OneClass(models.Model):
22 | name = models.CharField(max_length=50)
23 | teacher = models.ForeignKey('Teacher', on_delete=models.CASCADE)
24 | student = models.ForeignKey('Student', on_delete=models.CASCADE)
25 |
--------------------------------------------------------------------------------
/StudentInfoWebApp/urls.py:
--------------------------------------------------------------------------------
1 | """StudentInfoWebApp URL Configuration
2 |
3 | The `urlpatterns` list routes URLs to views. For more information please see:
4 | https://docs.djangoproject.com/en/2.0/topics/http/urls/
5 | Examples:
6 | Function views
7 | 1. Add an import: from my_app import views
8 | 2. Add a URL to urlpatterns: path('', views.home, name='home')
9 | Class-based views
10 | 1. Add an import: from other_app.views import Home
11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12 | Including another URLconf
13 | 1. Import the include() function: from django.urls import include, path
14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15 | """
16 | from django.conf.urls import url
17 | from django.contrib import admin
18 | from django.urls import path
19 |
20 | from StudentInfo.views import index, \
21 | add, delete, query, update
22 |
23 | urlpatterns = [
24 | # path('admin/', admin.site.urls),
25 | url(r'^index/$', index),
26 | url(r'^add/$', add),
27 | url(r'^delete/$', delete),
28 | url(r'^query/$', query),
29 | url(r'^update/$', update)
30 | ]
31 |
--------------------------------------------------------------------------------
/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 学生信息管理系统
6 |
7 |
8 |
9 |
10 |
30 |
31 |
--------------------------------------------------------------------------------
/.idea/StudentInfoWebApp.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/templates/add.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 添加学生信息
6 |
7 |
8 |
9 |
38 |
39 |
56 |
--------------------------------------------------------------------------------
/templates/delete.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 删除学生信息
6 |
7 |
8 |
9 |
10 |
13 |
14 |
22 |
23 | {#
#}
24 | {# {% if stu is not None %}#}
25 | {#
你删除的学生记录信息如下:
#}
26 | {# name = {{ stu.name }} age = {{ stu.age }} learn = {{ stu.learn }}
#}
27 | {# #}
28 | {# {% endif %}#}
29 | {# #}
30 |
33 |
34 |
37 |
38 |
39 |
54 |
--------------------------------------------------------------------------------
/templates/update.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 更新学生信息
6 |
7 |
8 |
9 |
39 |
40 |
57 |
--------------------------------------------------------------------------------
/templates/query.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 查询学生信息
6 |
7 |
8 |
9 |
10 |
13 |
14 |
21 |
22 | {% if stu is not None %}
23 |
name = {{ stu.name }}
age = {{ stu.age }}
learn = {{ stu.learn }}
24 | {% endif %}
25 |
26 |
27 | {#
name = {{ stu.name }}
age = {{ stu.age }}
learn = {{ stu.learn }}
#}
28 | {# 表格测试#}
29 |
30 | 学生信息查询结果列表
31 |
32 |
33 | | 序号 |
34 | 姓名 |
35 | 年龄 |
36 | 学科 |
37 |
38 |
39 |
40 |
41 | | {{ stu.name }} |
42 | {{ stu.age }} |
43 | {{ stu.learn }} |
44 |
45 |
46 |
47 |
48 |
51 |
52 |
55 |
56 |
57 |
66 |
--------------------------------------------------------------------------------
/StudentInfo/views.py:
--------------------------------------------------------------------------------
1 | from django.http import HttpResponse
2 | from django.shortcuts import render
3 | from StudentInfo.models import Student, OneClass
4 |
5 |
6 | # from django.http import request
7 | # Create your views here.
8 | def index(request):
9 | return render(request, 'index.html')
10 |
11 |
12 | def add(request):
13 | name = request.GET.get('name')
14 | age = request.GET.get('age')
15 | learn = request.GET.get('learn')
16 | type1 = request.GET.get('type1')
17 | # type 为1表示执行数据库操作,否则只是跳转页面
18 | if type1 == '1':
19 | Student.objects.create(name=name, age=age, learn=learn) # 在student 表里新建一条记录
20 | # return render(request, 'add.html',)
21 | return render(request, 'add.html')
22 |
23 |
24 | def delete(request):
25 | name = request.GET.get('name')
26 | type1 = request.GET.get('type1')
27 | # type 为 1 表示执行数据库查询操作
28 | # if type1 == '1':
29 | # # 查询所在记录
30 | # try:
31 | # stu: Student = Student.objects.filter(name=name).get()
32 | # except Exception:
33 | # return HttpResponse("无此记录")
34 | # return render(request, 'delete.html', {'stu': stu})
35 | # type 为 2 表示执行数据库确认删除操作
36 | if type1 == '2':
37 | try:
38 | Student.objects.filter(name=name).get()
39 | except Exception:
40 | return HttpResponse("无此记录")
41 | Student.objects.filter(name=name).delete()
42 | return render(request, 'delete.html', {'msg': '删除成功'})
43 | return render(request, 'delete.html')
44 |
45 |
46 | def update(request):
47 | name = request.GET.get('name')
48 | age = request.GET.get('age')
49 | learn = request.GET.get('learn')
50 | type1 = request.GET.get('type1')
51 | # type 为1表示执行数据库操作,否则只是跳转页面
52 | if type1 == '1':
53 | stu = Student.objects.get(name=name)
54 | stu.name = name
55 | stu.age = age
56 | stu.learn = learn
57 | stu.save()
58 | return render(request, "update.html", {'msg': '修改成功'})
59 | return render(request, 'update.html')
60 |
61 |
62 | def query(request):
63 | name = request.GET.get('name')
64 | type1 = request.GET.get('type1')
65 | # type 为1表示执行数据库操作,否则只是跳转页面
66 | if type1 == '1':
67 | if name == 'all':
68 | stu_list = Student.objects.all()
69 | return render(request, 'query.html', {'stu_list': stu_list})
70 | try:
71 | Student.objects.filter(name=name).get()
72 | except Exception:
73 | return HttpResponse("无此记录")
74 | stu = Student.objects.get(name=name) # 在student 表里查询一条记录
75 | return render(request, 'query.html', {'stu': stu})
76 |
77 | return render(request, 'query.html')
78 |
--------------------------------------------------------------------------------
/static/css/common.css:
--------------------------------------------------------------------------------
1 | .common {
2 | margin: 0 auto;
3 | width: 72%;
4 | min-width: 980px;
5 | background-color: #fff;
6 | padding: 30px;
7 | margin-top: 50px;
8 | margin-bottom: 50px;
9 | box-shadow: 0 2px 6px rgba(100, 100, 100, 0.3);
10 | }
11 |
12 | .stu-header {
13 | padding-bottom: 5px;
14 | margin-top: 10px;
15 | text-align: center;
16 | font-family: 隶书;
17 | /*font-style: italic;*/
18 | }
19 |
20 | .stu-center {
21 | width: 100%;
22 | text-align: left;
23 | margin-top: 30px;
24 | }
25 |
26 | .stu-footer {
27 | color: #686868;
28 | text-align: center;
29 | min-height: 15px;
30 | _height: 15px;
31 | border-top: 1px solid #ededed;
32 | margin-top: 50px;
33 | padding-top: 10px;
34 | margin-bottom: 10px;
35 | position: center;
36 | }
37 |
38 | .stu-form {
39 | width: 100%;
40 | height: 60%;
41 | position: center;
42 | text-align: center;
43 | /*font-family: 隶书;*/
44 | /*background: darksalmon;*/
45 | }
46 |
47 | .stu-line{
48 | margin: 5px;
49 | padding: 2px;
50 | position: center;
51 | text-align: center;
52 | }
53 |
54 | .stu-btn {
55 | /*background-color: #88bb77;*/
56 | /*border: none;*/
57 | /*color: white;*/
58 | /*padding: 15px 32px;*/
59 | /*text-align: center;*/
60 | /*text-decoration: none;*/
61 | /*display: inline-block;*/
62 | /*font-size: 16px;*/
63 | }
64 |
65 | .stu-table{
66 | /*width: 100%;*/
67 | /*height: 30%;*/
68 | position: center;
69 | align-items: center;
70 | /*text-align: center;*/
71 | /*background: aqua;*/
72 | }
73 |
74 | table {
75 | background-color: #FFF;
76 | border: none;
77 | color: #565;
78 | font: 12px arial;
79 | }
80 |
81 | table caption {
82 | font-size: 24px;
83 | border-bottom: 2px solid #B3DE94;
84 | border-top: 2px solid #B3DE94;
85 | }
86 |
87 | table, td, th {
88 | margin: 0;
89 | padding: 0;
90 | vertical-align: middle;
91 | text-align:left;
92 | }
93 |
94 | tbody td, tbody th {
95 | background-color: #DFC;
96 | border-bottom: 2px solid #B3DE94;
97 | border-top: 3px solid #FFFFFF;
98 | padding: 9px;
99 | }
100 |
101 |
102 | tfoot td, tfoot th {
103 | font-weight: bold;
104 | padding: 4px 8px 6px 9px;
105 | text-align:center;
106 | }
107 |
108 | thead th {
109 | font-size: 14px;
110 | font-weight: bold;
111 | line-height: 19px;
112 | padding: 0 8px 2px;
113 | text-align:center;
114 | }
115 |
116 | tbody tr.odd th,tbody tr.odd td { /*odd就是偶数行*/
117 | background-color: #CEA;
118 | border-bottom: 2px solid #67BD2A;
119 | }
120 |
121 | td+td+td, /*第三个td以及之后的td元素*/
122 | col.price{ /*类样式*/
123 | text-align:right;
124 | }
125 |
126 | tbody tr:hover td, tbody tr:hover th { /*tr也有hover样式*/
127 | background-color: #8b7;
128 | color:#fff;
129 | }
130 |
131 |
--------------------------------------------------------------------------------
/StudentInfoWebApp/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for StudentInfoWebApp project.
3 |
4 | Generated by 'django-admin startproject' using Django 2.0.6.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/2.0/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/2.0/ref/settings/
11 | """
12 |
13 | import os
14 |
15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17 |
18 |
19 | # Quick-start development settings - unsuitable for production
20 | # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
21 |
22 | # SECURITY WARNING: keep the secret key used in production secret!
23 | SECRET_KEY = 'uo58)(37bki)ggu83nk75ab_(9zp*f^4o&18xiv&2^istey4qb'
24 |
25 | # SECURITY WARNING: don't run with debug turned on in production!
26 | DEBUG = True
27 |
28 | ALLOWED_HOSTS = []
29 |
30 |
31 | # Application definition
32 |
33 | INSTALLED_APPS = [
34 | 'django.contrib.admin',
35 | 'django.contrib.auth',
36 | 'django.contrib.contenttypes',
37 | 'django.contrib.sessions',
38 | 'django.contrib.messages',
39 | 'django.contrib.staticfiles',
40 | 'StudentInfo'
41 | ]
42 |
43 | MIDDLEWARE = [
44 | 'django.middleware.security.SecurityMiddleware',
45 | 'django.contrib.sessions.middleware.SessionMiddleware',
46 | 'django.middleware.common.CommonMiddleware',
47 | 'django.middleware.csrf.CsrfViewMiddleware',
48 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
49 | 'django.contrib.messages.middleware.MessageMiddleware',
50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
51 | ]
52 |
53 | ROOT_URLCONF = 'StudentInfoWebApp.urls'
54 |
55 | TEMPLATES = [
56 | {
57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
58 | 'DIRS': [os.path.join(BASE_DIR, 'templates')]
59 | ,
60 | 'APP_DIRS': True,
61 | 'OPTIONS': {
62 | 'context_processors': [
63 | 'django.template.context_processors.debug',
64 | 'django.template.context_processors.request',
65 | 'django.contrib.auth.context_processors.auth',
66 | 'django.contrib.messages.context_processors.messages',
67 | ],
68 | },
69 | },
70 | ]
71 |
72 | WSGI_APPLICATION = 'StudentInfoWebApp.wsgi.application'
73 |
74 |
75 | # Database
76 | # https://docs.djangoproject.com/en/2.0/ref/settings/#databases
77 |
78 | DATABASES = {
79 | 'default': {
80 | 'ENGINE': 'django.db.backends.mysql',
81 | 'NAME': 'db_student',
82 | 'USER': 'root',
83 | 'PASSWORD': '123456',
84 | 'HOST': '127.0.0.1',
85 | 'PORT': '3306',
86 | }
87 | }
88 |
89 |
90 | # Password validation
91 | # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
92 |
93 | AUTH_PASSWORD_VALIDATORS = [
94 | {
95 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
96 | },
97 | {
98 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
99 | },
100 | {
101 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
102 | },
103 | {
104 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
105 | },
106 | ]
107 |
108 |
109 | # Internationalization
110 | # https://docs.djangoproject.com/en/2.0/topics/i18n/
111 |
112 | LANGUAGE_CODE = 'en-us'
113 |
114 | TIME_ZONE = 'UTC'
115 |
116 | USE_I18N = True
117 |
118 | USE_L10N = True
119 |
120 | USE_TZ = True
121 |
122 |
123 | # Static files (CSS, JavaScript, Images)
124 | # https://docs.djangoproject.com/en/2.0/howto/static-files/
125 |
126 | STATIC_URL = '/static/'
127 | HERE = os.path.dirname(os.path.abspath(__file__))
128 | HERE = os.path.join(HERE, '../')
129 | STATICFILES_DIRS = (
130 | # Put strings here, like "/home/html/static" or "C:/www/django/static".
131 | # Always use forward slashes, even on Windows.
132 | # Don't forget to use absolute paths, not relative paths.
133 | os.path.join(HERE, 'static/'),
134 | )
135 |
--------------------------------------------------------------------------------