“Django之在线考试与自动评分”的版本间的差异
来自CloudWiki
(创建页面,内容为“ == 技术要点 == 1)通过GET方式提交参数; 2)随机抽题; 3)客观题自动评分。 ==实施步骤== ===增加数据模型=== 1、修改ap…”) |
|||
第14行: | 第14行: | ||
1、修改apps\questions文件夹中的models.py文件,增加Test模型。 | 1、修改apps\questions文件夹中的models.py文件,增加Test模型。 | ||
+ | |||
+ | <nowiki>class Test(models.Model): | ||
+ | id = models.AutoField(primary_key=True) | ||
+ | questionID = models.IntegerField('题目编号') | ||
+ | account = models.CharField('学生账号',max_length=50) | ||
+ | testTime = models.DateTimeField('答题时间',auto_now=True) | ||
+ | stuAnswer = models.CharField('学生答案',max_length=50) | ||
+ | standardAnswer = models.CharField('标准答案',max_length=50,null=True) | ||
+ | batch = models.IntegerField('考试批次')</nowiki> | ||
2、执行命令,更新数据库。 | 2、执行命令,更新数据库。 | ||
+ | <nowiki>PS D:\teaching\python\实训\onLinePythonLearning> python manage.py makemigrations | ||
+ | Migrations for 'questions3': | ||
+ | questions3\migrations\0002_test.py | ||
+ | - Create model Test | ||
+ | PS D:\teaching\python\实训\onLinePythonLearning> python manage.py migrate | ||
+ | Operations to perform: | ||
+ | Apply all migrations: admin, auth, contenttypes, questions3, sessions | ||
+ | Running migrations: | ||
+ | Applying questions3.0002_test... OK</nowiki> | ||
+ | ===创建模板文件=== | ||
3、在apps\questions\templates\questions文件夹中创建模板文件test.html。 | 3、在apps\questions\templates\questions文件夹中创建模板文件test.html。 | ||
+ | |||
+ | <nowiki><html> | ||
+ | <head> | ||
+ | <meta charset="utf-8" /> | ||
+ | <title>在线测试</title> | ||
+ | </head> | ||
+ | <body> | ||
+ | <form method="get" action="/check/test/"> | ||
+ | {% if question %} | ||
+ | <h3>【{{num}}】/100】 {{ question.questionContent }}</h3> | ||
+ | <label>请输入答案: </label> | ||
+ | <input type="text" name="stuAnswer" required="required" /> | ||
+ | <br /> | ||
+ | <input type="text" style="display:none" name="id" value="{{question.id}}" /> | ||
+ | <input type="submit" value="下一题" /> | ||
+ | {% endif %} | ||
+ | |||
+ | </form> | ||
+ | |||
+ | </body> | ||
+ | </html></nowiki> | ||
2019年2月13日 (三) 07:01的最新版本
技术要点
1)通过GET方式提交参数;
2)随机抽题;
3)客观题自动评分。
实施步骤
增加数据模型
1、修改apps\questions文件夹中的models.py文件,增加Test模型。
class Test(models.Model): id = models.AutoField(primary_key=True) questionID = models.IntegerField('题目编号') account = models.CharField('学生账号',max_length=50) testTime = models.DateTimeField('答题时间',auto_now=True) stuAnswer = models.CharField('学生答案',max_length=50) standardAnswer = models.CharField('标准答案',max_length=50,null=True) batch = models.IntegerField('考试批次')
2、执行命令,更新数据库。
PS D:\teaching\python\实训\onLinePythonLearning> python manage.py makemigrations Migrations for 'questions3': questions3\migrations\0002_test.py - Create model Test PS D:\teaching\python\实训\onLinePythonLearning> python manage.py migrate Operations to perform: Apply all migrations: admin, auth, contenttypes, questions3, sessions Running migrations: Applying questions3.0002_test... OK
创建模板文件
3、在apps\questions\templates\questions文件夹中创建模板文件test.html。
<html> <head> <meta charset="utf-8" /> <title>在线测试</title> </head> <body> <form method="get" action="/check/test/"> {% if question %} <h3>【{{num}}】/100】 {{ question.questionContent }}</h3> <label>请输入答案: </label> <input type="text" name="stuAnswer" required="required" /> <br /> <input type="text" style="display:none" name="id" value="{{question.id}}" /> <input type="submit" value="下一题" /> {% endif %} </form> </body> </html>
4.1、修改apps\questions文件夹中的views.py文件,增加下面的导入。
4.2、增加用来检查是否登录的修饰器。
4.3、然后增加用来考试的函数test()。
5、修改apps\questions文件夹中的urls.py文件,增加一条路由。
6.1、执行命令,运行网站,然后使用浏览器登录,进入考试页面。
6.2、考试结束,直接给出成绩。