update studentmanagement
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
*.idea
|
||||
/.idea/
|
||||
/__pycache__/
|
||||
__pycache__/
|
||||
__pycache__
|
||||
@@ -0,0 +1,131 @@
|
||||
"""
|
||||
Django settings for StudentSystem project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 2.1.7.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/2.1/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/2.1/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = '3%i9ky+d^l3ryt5$1a&3g*(=(w@_h0ts9gh$gjt-@gdtjgs99_'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'studentManagement',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'StudentSystem.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [os.path.join(BASE_DIR, 'templates')],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'StudentSystem.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': 'studentmanager',
|
||||
'USER': 'root',
|
||||
'PASSWORD': '123456'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/2.1/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'zh-hans'
|
||||
|
||||
TIME_ZONE = 'Asia/Shanghai'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/2.1/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATICFILES_DIRS = [
|
||||
|
||||
os.path.join(BASE_DIR, 'static')
|
||||
]
|
||||
|
||||
if __name__=='__main__':
|
||||
print(os.path.join(BASE_DIR, 'static'))
|
||||
print('h')
|
||||
@@ -0,0 +1,25 @@
|
||||
"""StudentSystem URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/2.1/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
from django.conf.urls import url
|
||||
urlpatterns = [
|
||||
path('', include('studentManagement.urls', namespace='student')),
|
||||
path('student/', include('studentManagement.urls')),
|
||||
path('admin/', admin.site.urls)
|
||||
# url(r'^admin/', admin.site.urls),
|
||||
# url(r'^', include('studentManagement.urls', namespace='student'))
|
||||
]
|
||||
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for StudentSystem project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'StudentSystem.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
if __name__ == '__main__':
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'StudentSystem.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
@@ -0,0 +1,31 @@
|
||||
from django.contrib import admin
|
||||
from studentManagement.models import StudentInformationModel, CourseModel, StudentModel
|
||||
# Register your models here.
|
||||
|
||||
class StudentInformationLine(admin.TabularInline):
|
||||
model = CourseModel
|
||||
extra = 3
|
||||
|
||||
|
||||
class StudentInformationAdmin(admin.ModelAdmin):
|
||||
# 显示的字段,先后顺序表示显示顺序
|
||||
list_display = ['stu_id', 'stu_name', 'stu_phone', 'str_addr', 'stu_faculty', 'stu_major']
|
||||
# 以哪个来过滤
|
||||
list_filter = ['stu_id', 'stu_name']
|
||||
# 以哪个字段来搜索,admin中就会出现一个搜索栏
|
||||
search_fields = ['stu_name', 'str_addr', 'stu_faculty', 'stu_major']
|
||||
list_per_page = 5
|
||||
|
||||
class CourseAdmin(admin.ModelAdmin):
|
||||
list_display = ['cour_id', 'course', 'grade']
|
||||
# inlines = [StudentInformationLine, ] # 谁的外键就写在哪边
|
||||
|
||||
class StudentAdmin(admin.ModelAdmin):
|
||||
list_display = ['stu_id', 'username', 'password']
|
||||
search_fields = ['stu_id', 'username']
|
||||
actions_on_top = False
|
||||
actions_on_bottom = True
|
||||
|
||||
admin.site.register(StudentInformationModel, StudentInformationAdmin)
|
||||
admin.site.register(CourseModel, CourseAdmin)
|
||||
admin.site.register(StudentModel, StudentAdmin)
|
||||
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class StudentmanagementConfig(AppConfig):
|
||||
name = 'studentManagement'
|
||||
@@ -0,0 +1,52 @@
|
||||
# Generated by Django 3.0.3 on 2020-08-03 09:06
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CourseModel',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('cour_id', models.CharField(max_length=15, verbose_name='学生ID')),
|
||||
('course', models.CharField(max_length=30, verbose_name='课程')),
|
||||
('grade', models.IntegerField(default=60, verbose_name='分数')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'course',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='StudentInformationModel',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('stu_id', models.CharField(max_length=15, verbose_name='学生ID')),
|
||||
('stu_name', models.CharField(max_length=30, verbose_name='学生姓名')),
|
||||
('stu_phone', models.CharField(max_length=20, verbose_name='学生电话')),
|
||||
('str_addr', models.TextField(verbose_name='学生地址')),
|
||||
('stu_faculty', models.CharField(max_length=20, verbose_name='院系')),
|
||||
('stu_major', models.CharField(max_length=30, verbose_name='专业')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'studentinformation',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='StudentModel',
|
||||
fields=[
|
||||
('stu_id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('username', models.CharField(max_length=10, verbose_name='用户名')),
|
||||
('password', models.CharField(max_length=10, verbose_name='密码')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'student',
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,34 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
# 课程表
|
||||
class CourseModel(models.Model):
|
||||
cour_id = models.CharField(max_length=15, verbose_name='学生ID')
|
||||
course = models.CharField(max_length=30, verbose_name='课程')
|
||||
grade = models.IntegerField(default=60, verbose_name='分数')
|
||||
class Meta():
|
||||
db_table = 'course'
|
||||
def __str__(self):
|
||||
return '学生Id: 课程: 分数: '.format(self.cour_id, self.course, self.grade)
|
||||
|
||||
# 学生信息表
|
||||
class StudentInformationModel(models.Model):
|
||||
stu_id = models.CharField(max_length=15, verbose_name='学生ID')
|
||||
stu_name = models.CharField(max_length=30, verbose_name='学生姓名')
|
||||
stu_phone = models.CharField(max_length=20, verbose_name='学生电话')
|
||||
str_addr = models.TextField(verbose_name='学生地址')
|
||||
stu_faculty = models.CharField(max_length=20, verbose_name='院系')
|
||||
stu_major = models.CharField(max_length=30, verbose_name='专业')
|
||||
# 取消外键(外键是可用的)
|
||||
# stu_course = models.ForeignKey('CourseModel', on_delete=True)
|
||||
class Meta():
|
||||
db_table = 'studentinformation'
|
||||
|
||||
# 学生用户名密码表
|
||||
class StudentModel(models.Model):
|
||||
stu_id = models.AutoField(primary_key=True)
|
||||
username = models.CharField(max_length=10, verbose_name='用户名')
|
||||
password = models.CharField(max_length=10, verbose_name='密码')
|
||||
class Meta():
|
||||
db_table = 'student'
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -0,0 +1,15 @@
|
||||
from django.urls import path
|
||||
from studentManagement import views
|
||||
from django.conf.urls import url
|
||||
app_name = 'studentManager'
|
||||
urlpatterns = [
|
||||
path('', views.index),
|
||||
path('index/', views.index, name='index'),
|
||||
path('login/', views.login, name='login'),
|
||||
path('regist/', views.regist, name='regist'),
|
||||
path('logout/', views.logout, name='logout'),
|
||||
path('add/', views.add, name='add'),
|
||||
path('select/', views.select, name='select'),
|
||||
path('delete/', views.delete, name='delete'),
|
||||
path('update/', views.update, name='update')
|
||||
]
|
||||
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>请在下列信息栏中填入学生的基本信息</h1>
|
||||
<form method="post" action="{% url 'student:add' %}">
|
||||
{% csrf_token %}
|
||||
学生学号:<input type="text" name="stu_id"/><br>
|
||||
学生姓名:<input type="text" name="stu_name"/><br>
|
||||
{% if msg %}
|
||||
<h5>{{ msg }}</h5><br>
|
||||
{% endif %}
|
||||
学生电话:<input type="text" name="stu_phone"/><br>
|
||||
学生地址:<input type="text" name="str_addr"/><br>
|
||||
学生院系:<input type="text" name="stu_faculty"/><br>
|
||||
学生专业:<input type="text" name="stu_major"/><br>
|
||||
<input class="bc" type="submit" value="保存"/>
|
||||
{% if error %}
|
||||
<h5>{{ error }}</h5><br>
|
||||
{% endif %}
|
||||
{% if sucess %}
|
||||
<h5>{{ sucess }}</h5><br>
|
||||
{% endif %}
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>请输入你要想要删除的学生学号</h1>
|
||||
<form method="post" action="/student/delete/">
|
||||
{% csrf_token %}
|
||||
学生学号:<input type="text" name="stu_id" placeholder={{ id }}><br>
|
||||
<input class="bc" type="submit" value="删除">
|
||||
</form>
|
||||
{% if msg %}
|
||||
{{ msg }}
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<br>
|
||||
{% if lenght %}
|
||||
<a href="/student/logout/">退出</a><br>
|
||||
<h1 style="color: blue">欢迎{{ status}},来到学生信息管理系统</h1><br>
|
||||
<h3 style="color: green">请选择你要执行的功能</h3>
|
||||
<a href="{% url 'student:add' %}">增加学生信息</a><br>
|
||||
<a href="{% url 'student:select' %}">查询学生信息</a><br>
|
||||
<a href="{% url 'student:delete' %}">删除学生信息</a><br>
|
||||
<a href="{% url 'student:update' %}">修改学生信息</a><br>
|
||||
{% else %}
|
||||
<a href="student/login/">登录</a><br>
|
||||
<a href="student/regist/">注册</a><br>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
你好: {{ status }}
|
||||
<form method="post" action="/student/login/">
|
||||
{% csrf_token %}
|
||||
<input type="text" name="username" placeholder="用户名:"/><br>
|
||||
<input type="password" name="password" placeholder="密 码:"/><br>
|
||||
<input class="tj" type="submit" value="登录"/>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>根据学号来查询学习基本信息及选课情况Izhe</h1>
|
||||
{% if not msg %}
|
||||
{# 判断是否由msg这个参数,或者判断其值,没有的话则执行这段代码#}
|
||||
<form method="post" action="/student/select/">
|
||||
{% csrf_token %}
|
||||
学生学号:<input type="text" name="stu_id" placeholder={{ id }}><br>
|
||||
<input class="bc" type="submit" value="查询">
|
||||
</form>
|
||||
{% else %}
|
||||
<ul>
|
||||
<li>学号: {{ stu_id }}</li>
|
||||
<li>姓名: {{ stu_name }}</li>
|
||||
<li>电话: {{ stu_phone }}</li>
|
||||
<li>地址: {{ str_addr }}</li>
|
||||
<li>院系: {{ stu_faculty }}</li>
|
||||
<li>专业: {{ stu_major }}</li>
|
||||
</ul>
|
||||
<hr>
|
||||
<ul>
|
||||
{% for k, v in course_data.items %}
|
||||
<li>{{ k }}: {{ v }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>根据学号来修改学生基本信息</h1>
|
||||
<form method="post" action="/student/update/">
|
||||
{% csrf_token %}
|
||||
学生学号:<input type="text" name="stu_id" placeholder={{ stu_id }}><br>
|
||||
学生姓名:<input type="text" name="stu_name" placeholder={{ stu_name }}><br>
|
||||
学生电话:<input type="text" name="stu_phone" placeholder={{ stu_phone }}><br>
|
||||
学生地址:<input type="text" name="stu_addr" placeholder={{ stu_addr }}><br>
|
||||
学生院系:<input type="text" name="stu_faculty" placeholder={{ stu_faculty }}><br>
|
||||
学生专业:<input type="text" name="stu_major" placeholder={{ stu_major }}><br>
|
||||
<input class="bc" type="submit" value="保存">
|
||||
</form>
|
||||
{% if msg %}
|
||||
{{ msg }}
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user