Python-django在线考试系统搭建[前端+后端 ]

一:项目目标:

1,制作一个学生端:可以登录,在线考试,查看成绩.教师端:可以进行组卷,分析试卷,查看学生成绩.管理员端可以进行数据修改.

2,主要运用的技术:前端(bootstrap+jQuery+html+js+css)后端(django2.0+Python)数据库(MySQL).

3,使用流程:教师组卷--------学生接收试卷--------学生在线考试------------考试结束----------系统分析学生成绩----------教师查看成绩.

4,不足点<系统没有设计防作弊的系统>

二:项目过程:

1,分析表与表之间的关系如下图:

Python-django在线考试系统搭建[前端+后端 ]_第1张图片

2,分析完表之后在合适的目录下创建项目还是老三样(创建项目这里不做说明,可以搜索自学堂查看django相关教程)

3,配置stting文件(主要激活应用,添加APP,改汉语,修改数据库)

"""
Django settings for exm_project project.

Generated by 'django-admin startproject' using Django 2.0.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/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.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '(@cj^i*y#owss&s$nu=cuu%h931hcq$*gx)0vq@06+g@s#-akp'

# 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',
    'student',

]

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 = 'exm_project.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 = 'exm_project.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'exam',
        'USER':'root',
        'PASSWORD':'root',
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.0/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.0/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.0/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [
	os.path.join(BASE_DIR,'templates'),


]

4,大家一定不能忘记在_init_.py中添加import pymysql
pymysql.install_as_MySQLdb()不然会报错

5,表的设计:<将代码写在创建的APP目录下的models中>

from django.db import models

# Create your models here.
SEX=(
	('男','男'),
	('女','女'),
)

DEPT=(
	('计算机与通信学院','计算机与通信学院'),
	('电气与自动化学院','电气与自动化学院'),
	('外国语学院','外国语学院'),
	('理学院','理学院'),
)

class Student(models.Model):
	id = models.CharField('学号',max_length=20,primary_key=True)
	name = models.CharField('姓名',max_length=20)
	sex = models.CharField('性别',max_length=4,choices=SEX,default='男')
	dept = models.CharField('学院',max_length=20,choices=DEPT,default=None)
	major = models.CharField('专业',max_length=20,default=None)
	password = models.CharField('密码',max_length=20,default='111')
	email = models.EmailField('邮箱',default=None)
	birth = models.DateField('出生日期')

	class Meta:
		db_table='student'
		verbose_name='学生'
		verbose_name_plural=verbose_name

		def __str__(self):
			return self.id;

class Teacher(models.Model):
	id = models.CharField('教工号',max_length=20,primary_key=True)
	name = models.CharField('姓名',max_length=20)
	sex = models.CharField('性别',max_length=4,choices=SEX,default='男')
	dept = models.CharField('学院',max_length=20,choices=DEPT,default=None)
	email = models.EmailField('邮箱',default=None)
	password = models.CharField('密码',max_length=20,default='000000')
	birth = models.DateField('出生日期')

	class Meta:
		db_table='teacher'
		verbose_name='教师'
		verbose_name_plural=verbose_name

		def __str__(self):
			return self.name;


class Question(models.Model):
	ANSWER=(
		('A','A'),
		('B','B'),
		('C','C'),
		('D','D'),
)
	LEVEL={
		('1','easy'),
		('2','general'),
		('3','difficult'),
}
	id = models.AutoField(primary_key=True)
	subject = models.CharField('科目',max_length=20)
	title = models.TextField('题目')
	optionA = models.CharField('A选项',max_length=30)
	optionB = models.CharField('B选项',max_length=30)
	optionC = models.CharField('C选项',max_length=30)
	optionD = models.CharField('D选项',max_length=30)
	answer = models.CharField('答案',max_length=10,choices=ANSWER)
	level = models.CharField('等级',max_length=10,choices=LEVEL)
	score = models.IntegerField('分数',default=1)


	class Meta:
		db_table='question'
		verbose_name='单项选择题'
		verbose_name_plural=verbose_name

		def __str__(self):
			return '<%s:%s>'%(self.subject,self.title);

class Paper(models.Model):
    pid=models.ManyToManyField(Question)
    tid=models.ForeignKey(Teacher,on_delete=models.CASCADE)
    subject=models.CharField('科目',max_length=20,default='')
    major=models.CharField('考卷适用专业',max_length=20)
    examtime=models.DateTimeField()


    class Meta:
        db_table='paper'
        verbose_name='试卷'
        verbose_name_plural=verbose_name
    def __str__(self):
        return self.major;

class Grade(models.Model):
    sid=models.ForeignKey(Student,on_delete=models.CASCADE,default='')#添加外键
    subject=models.CharField('科目',max_length=20,default='')
    grade=models.IntegerField()

    def __str__(self):
        return '<%s:%s>'%(self.sid,self.grade);

    class Meta:
        db_table='grade'
        verbose_name='成绩'
        verbose_name_plural=verbose_name

6,生成迁移文件

python manage.py makemigrations

python manage.py migrate

7,一切准备就绪之后,我们进行路由,模板和视图的制作.

urls.py

from django.contrib import admin
from django.urls import path
from student.views import *
urlpatterns = [
    path('admin/', admin.site.urls),
    path('',index),


views.py

from django.shortcuts import render,redirect
from student import models
from django.http import HttpResponse
from django.contrib.auth import logout
# Create your views here.



def index(request):
	return render(request,'index.html')








    
    


    
    
    
    

    
    

    在线考试系统








学生信息

属性 信息
学号 { { student.id }}
姓名 { { student.name }}
性别 { { student.sex }}
学院 { { student.dept }}
专业 { { student.major }}
邮箱地址 { { student.email }}
出生日期 { { student.birth }}
{#学生登录的模态对话框#} {#老师登录的模态对话框#}

江苏农林职业技术学院 © 2020, All Rights Reserved

在模板中我们将bootstrap使用cdn引入

8,完成路由的配置,我们打开cmd   到相应位置输入python   manage.py  runserver

9,到浏览器输入http://127.0.0.1:8000/即可看到如下内容:

Python-django在线考试系统搭建[前端+后端 ]_第2张图片

10,明天我们进行学生登录,教师登录的制作.

你可能感兴趣的:(前端+后端,html,jquery,javascript,python,django)