diff --git a/pythonProject03/.idea/.gitignore b/pythonProject03/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/pythonProject03/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/pythonProject03/.idea/encodings.xml b/pythonProject03/.idea/encodings.xml
new file mode 100644
index 0000000..46a6cc4
--- /dev/null
+++ b/pythonProject03/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject03/.idea/inspectionProfiles/profiles_settings.xml b/pythonProject03/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/pythonProject03/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject03/.idea/misc.xml b/pythonProject03/.idea/misc.xml
new file mode 100644
index 0000000..5176999
--- /dev/null
+++ b/pythonProject03/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject03/.idea/modules.xml b/pythonProject03/.idea/modules.xml
new file mode 100644
index 0000000..f479868
--- /dev/null
+++ b/pythonProject03/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject03/.idea/pythonProject02.iml b/pythonProject03/.idea/pythonProject02.iml
new file mode 100644
index 0000000..2c80e12
--- /dev/null
+++ b/pythonProject03/.idea/pythonProject02.iml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject03/.idea/vcs.xml b/pythonProject03/.idea/vcs.xml
new file mode 100644
index 0000000..07e3a0f
--- /dev/null
+++ b/pythonProject03/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject03/mysite10_7/db.sqlite3 b/pythonProject03/mysite10_7/db.sqlite3
new file mode 100644
index 0000000..e69de29
diff --git a/pythonProject03/mysite10_7/manage.py b/pythonProject03/mysite10_7/manage.py
new file mode 100644
index 0000000..2620c38
--- /dev/null
+++ b/pythonProject03/mysite10_7/manage.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+"""Django's command-line utility for administrative tasks."""
+import os
+import sys
+
+
+def main():
+ """Run administrative tasks."""
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite10_7.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)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/pythonProject03/mysite10_7/mysite10_7/__init__.py b/pythonProject03/mysite10_7/mysite10_7/__init__.py
new file mode 100644
index 0000000..c45523b
--- /dev/null
+++ b/pythonProject03/mysite10_7/mysite10_7/__init__.py
@@ -0,0 +1,2 @@
+import pymysql
+pymysql.install_as_MySQLdb()
\ No newline at end of file
diff --git a/pythonProject03/mysite10_7/mysite10_7/__pycache__/__init__.cpython-37.pyc b/pythonProject03/mysite10_7/mysite10_7/__pycache__/__init__.cpython-37.pyc
new file mode 100644
index 0000000..8a4fbc8
Binary files /dev/null and b/pythonProject03/mysite10_7/mysite10_7/__pycache__/__init__.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/mysite10_7/__pycache__/settings.cpython-37.pyc b/pythonProject03/mysite10_7/mysite10_7/__pycache__/settings.cpython-37.pyc
new file mode 100644
index 0000000..adf919a
Binary files /dev/null and b/pythonProject03/mysite10_7/mysite10_7/__pycache__/settings.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/mysite10_7/__pycache__/urls.cpython-37.pyc b/pythonProject03/mysite10_7/mysite10_7/__pycache__/urls.cpython-37.pyc
new file mode 100644
index 0000000..e84c00c
Binary files /dev/null and b/pythonProject03/mysite10_7/mysite10_7/__pycache__/urls.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/mysite10_7/__pycache__/wsgi.cpython-37.pyc b/pythonProject03/mysite10_7/mysite10_7/__pycache__/wsgi.cpython-37.pyc
new file mode 100644
index 0000000..276632d
Binary files /dev/null and b/pythonProject03/mysite10_7/mysite10_7/__pycache__/wsgi.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/mysite10_7/asgi.py b/pythonProject03/mysite10_7/mysite10_7/asgi.py
new file mode 100644
index 0000000..fcf9922
--- /dev/null
+++ b/pythonProject03/mysite10_7/mysite10_7/asgi.py
@@ -0,0 +1,16 @@
+"""
+ASGI config for mysite10_7 project.
+
+It exposes the ASGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
+"""
+
+import os
+
+from django.core.asgi import get_asgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite10_7.settings')
+
+application = get_asgi_application()
diff --git a/pythonProject03/mysite10_7/mysite10_7/settings.py b/pythonProject03/mysite10_7/mysite10_7/settings.py
new file mode 100644
index 0000000..ba343c4
--- /dev/null
+++ b/pythonProject03/mysite10_7/mysite10_7/settings.py
@@ -0,0 +1,130 @@
+"""
+Django settings for mysite10_7 project.
+
+Generated by 'django-admin startproject' using Django 3.2.25.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.2/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/3.2/ref/settings/
+"""
+import os.path
+from pathlib import Path
+
+# Build paths inside the project like this: BASE_DIR / 'subdir'.
+BASE_DIR = Path(__file__).resolve().parent.parent
+
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = 'django-insecure-50h(t$5-#_$h(#7)bdr-fr2)77c+v1$=n_0b82$z#*od_$_%ia'
+
+# 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',
+ 'polls'
+]
+
+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 = 'mysite10_7.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 = 'mysite10_7.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.mysql',
+ 'NAME': 'testdemo107',
+ 'USER':'root',
+ 'PASSWORD':'123456',
+ 'HOST':'127.0.0.1',
+ 'PORT':'3306'
+ }
+}
+
+
+# Password validation
+# https://docs.djangoproject.com/en/3.2/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/3.2/topics/i18n/
+
+LANGUAGE_CODE = 'en-us'
+
+TIME_ZONE = 'UTC'
+
+USE_I18N = True
+
+USE_L10N = True
+
+USE_TZ = True
+
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/3.2/howto/static-files/
+
+STATIC_URL = '/static/'
+
+# Default primary key field type
+# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
+
+DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
diff --git a/pythonProject03/mysite10_7/mysite10_7/urls.py b/pythonProject03/mysite10_7/mysite10_7/urls.py
new file mode 100644
index 0000000..b598653
--- /dev/null
+++ b/pythonProject03/mysite10_7/mysite10_7/urls.py
@@ -0,0 +1,23 @@
+"""mysite10_7 URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+ https://docs.djangoproject.com/en/3.2/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
+
+urlpatterns = [
+ path('admin/', admin.site.urls),
+ path('polls/', include('polls.urls')),
+
+]
diff --git a/pythonProject03/mysite10_7/mysite10_7/wsgi.py b/pythonProject03/mysite10_7/mysite10_7/wsgi.py
new file mode 100644
index 0000000..c25090f
--- /dev/null
+++ b/pythonProject03/mysite10_7/mysite10_7/wsgi.py
@@ -0,0 +1,16 @@
+"""
+WSGI config for mysite10_7 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/3.2/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite10_7.settings')
+
+application = get_wsgi_application()
diff --git a/pythonProject03/mysite10_7/polls/__init__.py b/pythonProject03/mysite10_7/polls/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/pythonProject03/mysite10_7/polls/__pycache__/__init__.cpython-37.pyc b/pythonProject03/mysite10_7/polls/__pycache__/__init__.cpython-37.pyc
new file mode 100644
index 0000000..f4256e4
Binary files /dev/null and b/pythonProject03/mysite10_7/polls/__pycache__/__init__.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/polls/__pycache__/admin.cpython-37.pyc b/pythonProject03/mysite10_7/polls/__pycache__/admin.cpython-37.pyc
new file mode 100644
index 0000000..5207c52
Binary files /dev/null and b/pythonProject03/mysite10_7/polls/__pycache__/admin.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/polls/__pycache__/apps.cpython-37.pyc b/pythonProject03/mysite10_7/polls/__pycache__/apps.cpython-37.pyc
new file mode 100644
index 0000000..b3e322c
Binary files /dev/null and b/pythonProject03/mysite10_7/polls/__pycache__/apps.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/polls/__pycache__/forms.cpython-37.pyc b/pythonProject03/mysite10_7/polls/__pycache__/forms.cpython-37.pyc
new file mode 100644
index 0000000..0ad500b
Binary files /dev/null and b/pythonProject03/mysite10_7/polls/__pycache__/forms.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/polls/__pycache__/models.cpython-37.pyc b/pythonProject03/mysite10_7/polls/__pycache__/models.cpython-37.pyc
new file mode 100644
index 0000000..8875192
Binary files /dev/null and b/pythonProject03/mysite10_7/polls/__pycache__/models.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/polls/__pycache__/urls.cpython-37.pyc b/pythonProject03/mysite10_7/polls/__pycache__/urls.cpython-37.pyc
new file mode 100644
index 0000000..2205bd2
Binary files /dev/null and b/pythonProject03/mysite10_7/polls/__pycache__/urls.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/polls/__pycache__/views.cpython-37.pyc b/pythonProject03/mysite10_7/polls/__pycache__/views.cpython-37.pyc
new file mode 100644
index 0000000..615fc7a
Binary files /dev/null and b/pythonProject03/mysite10_7/polls/__pycache__/views.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/polls/admin.py b/pythonProject03/mysite10_7/polls/admin.py
new file mode 100644
index 0000000..8c38f3f
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/pythonProject03/mysite10_7/polls/apps.py b/pythonProject03/mysite10_7/polls/apps.py
new file mode 100644
index 0000000..5a5f94c
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/apps.py
@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class PollsConfig(AppConfig):
+ default_auto_field = 'django.db.models.BigAutoField'
+ name = 'polls'
diff --git a/pythonProject03/mysite10_7/polls/forms.py b/pythonProject03/mysite10_7/polls/forms.py
new file mode 100644
index 0000000..7822394
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/forms.py
@@ -0,0 +1,6 @@
+from django import forms # 导入 Django 的表单模块
+
+# 定义文件上传表单类
+class UploadFileForm(forms.Form):
+ # 定义一个 FileField 用于处理文件上传,label 是显示在表单中的标签
+ file = forms.FileField(label="Select an Excel file")
diff --git a/pythonProject03/mysite10_7/polls/migrations/0001_initial.py b/pythonProject03/mysite10_7/polls/migrations/0001_initial.py
new file mode 100644
index 0000000..1237b4d
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/migrations/0001_initial.py
@@ -0,0 +1,22 @@
+# Generated by Django 3.2.25 on 2024-10-06 17:20
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='StudentInfo',
+ fields=[
+ ('stu_id', models.CharField(max_length=20, primary_key=True, serialize=False)),
+ ('stu_name', models.CharField(max_length=20)),
+ ('stu_pwd', models.CharField(max_length=20)),
+ ],
+ ),
+ ]
diff --git a/pythonProject03/mysite10_7/polls/migrations/0002_student.py b/pythonProject03/mysite10_7/polls/migrations/0002_student.py
new file mode 100644
index 0000000..b296350
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/migrations/0002_student.py
@@ -0,0 +1,23 @@
+# Generated by Django 3.2.25 on 2024-10-07 08:05
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('polls', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Student',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=100)),
+ ('student_id', models.CharField(max_length=100, unique=True)),
+ ('score', models.FloatField(default=0)),
+ ('attendance_count', models.IntegerField(default=0)),
+ ],
+ ),
+ ]
diff --git a/pythonProject03/mysite10_7/polls/migrations/__init__.py b/pythonProject03/mysite10_7/polls/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/pythonProject03/mysite10_7/polls/migrations/__pycache__/0001_initial.cpython-37.pyc b/pythonProject03/mysite10_7/polls/migrations/__pycache__/0001_initial.cpython-37.pyc
new file mode 100644
index 0000000..52dcbb5
Binary files /dev/null and b/pythonProject03/mysite10_7/polls/migrations/__pycache__/0001_initial.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/polls/migrations/__pycache__/0002_student.cpython-37.pyc b/pythonProject03/mysite10_7/polls/migrations/__pycache__/0002_student.cpython-37.pyc
new file mode 100644
index 0000000..ce6e33d
Binary files /dev/null and b/pythonProject03/mysite10_7/polls/migrations/__pycache__/0002_student.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/polls/migrations/__pycache__/__init__.cpython-37.pyc b/pythonProject03/mysite10_7/polls/migrations/__pycache__/__init__.cpython-37.pyc
new file mode 100644
index 0000000..b6e2c24
Binary files /dev/null and b/pythonProject03/mysite10_7/polls/migrations/__pycache__/__init__.cpython-37.pyc differ
diff --git a/pythonProject03/mysite10_7/polls/models.py b/pythonProject03/mysite10_7/polls/models.py
new file mode 100644
index 0000000..d6563c0
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/models.py
@@ -0,0 +1,22 @@
+from django.db import models
+
+# Create your models here.
+class StudentInfo(models.Model):
+ stu_id = models.CharField(primary_key=True, max_length=20)
+ stu_name = models.CharField(max_length=20)
+ stu_pwd = models.CharField(max_length=20)
+
+
+
+# -----
+from django.db import models
+
+# 学生表
+class Student(models.Model):
+ name = models.CharField(max_length=100)
+ student_id = models.CharField(max_length=100, unique=True) # 学号设为唯一
+ score = models.FloatField(default=0) # 积分允许为小数
+ attendance_count = models.IntegerField(default=0) # 到课次数
+
+ def __str__(self):
+ return self.name
diff --git a/pythonProject03/mysite10_7/polls/templates/__init__.py b/pythonProject03/mysite10_7/polls/templates/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/pythonProject03/mysite10_7/polls/templates/confirm_roll_call.html b/pythonProject03/mysite10_7/polls/templates/confirm_roll_call.html
new file mode 100644
index 0000000..b7c7ce3
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/templates/confirm_roll_call.html
@@ -0,0 +1,35 @@
+
+
+
+
+ 确认点名
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject03/mysite10_7/polls/templates/login.html b/pythonProject03/mysite10_7/polls/templates/login.html
new file mode 100644
index 0000000..4b3567f
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/templates/login.html
@@ -0,0 +1,15 @@
+
+
+
+
+ 登录
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject03/mysite10_7/polls/templates/register.html b/pythonProject03/mysite10_7/polls/templates/register.html
new file mode 100644
index 0000000..bb353f2
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/templates/register.html
@@ -0,0 +1,15 @@
+
+
+
+
+ 注册
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject03/mysite10_7/polls/templates/roll_call.html b/pythonProject03/mysite10_7/polls/templates/roll_call.html
new file mode 100644
index 0000000..fbd1afb
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/templates/roll_call.html
@@ -0,0 +1,19 @@
+
+
+
+
+ 随机点名
+
+
+
+
+{% if selected_student %}
+ 被选中的学生:
+ 姓名: {{ selected_student.name }}
+ 学号: {{ selected_student.student_id }}
+{% endif %}
+
+
\ No newline at end of file
diff --git a/pythonProject03/mysite10_7/polls/templates/upload_students.html b/pythonProject03/mysite10_7/polls/templates/upload_students.html
new file mode 100644
index 0000000..68bae50
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/templates/upload_students.html
@@ -0,0 +1,15 @@
+
+
+
+
+ Title
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pythonProject03/mysite10_7/polls/tests.py b/pythonProject03/mysite10_7/polls/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/pythonProject03/mysite10_7/polls/urls.py b/pythonProject03/mysite10_7/polls/urls.py
new file mode 100644
index 0000000..e9d2e41
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/urls.py
@@ -0,0 +1,11 @@
+from django.urls import path
+from . import views
+urlpatterns = [
+ path('',views.toLogin_view),
+ path('index/',views.Login_view),
+ path('toregister/',views.toregister_view),
+ path('register/',views.register_view),
+ path('upload/', views.upload_students, name='upload_students'),
+ path('roll_call/', views.roll_call, name='roll_call'),
+ path('confirm_roll_call/', views.confirm_roll_call, name='confirm_roll_call'), # 确认点名
+]
\ No newline at end of file
diff --git a/pythonProject03/mysite10_7/polls/views.py b/pythonProject03/mysite10_7/polls/views.py
new file mode 100644
index 0000000..9c8f2df
--- /dev/null
+++ b/pythonProject03/mysite10_7/polls/views.py
@@ -0,0 +1,103 @@
+from django.shortcuts import render
+from django.http import HttpResponse
+from .models import *
+from django.shortcuts import render, redirect, get_object_or_404
+import random
+import pandas as pd
+# 导入表单
+from .forms import UploadFileForm
+# Create your views here.
+def toLogin_view(request):
+ return render(request,'login.html')
+def Login_view(request):
+ u=request.POST.get("user",'')
+ p=request.POST.get("pwd",'')
+
+ if u and p:
+ c=StudentInfo.objects.filter(stu_name=u,stu_pwd=p).count()
+ if c >= 1:
+ return HttpResponse("登录成功!")
+ else:
+ return HttpResponse("账号密码错误!")
+ else:
+ return HttpResponse("请输入正确的账号和密码!")
+
+def toregister_view(request):
+ return render(request, 'register.html')
+
+ # #点击注册后做的逻辑判断
+def register_view(request):
+ u = request.POST.get("user", '')
+ p = request.POST.get("pwd", '')
+ if u and p:
+ stu = StudentInfo(stu_id=random.choice('0123456789'),stu_name=u, stu_pwd=p)
+ stu.save()
+ return HttpResponse("注册成功")
+ else:
+ return HttpResponse("请输入完整的账号和密码!")
+
+#导入excel
+# 上传学生名单的视图
+def upload_students(request):
+ if request.method == 'POST':
+ form = UploadFileForm(request.POST, request.FILES)
+ if form.is_valid():
+ # 读取上传的 Excel 文件
+ excel_file = request.FILES['file']
+ df = pd.read_excel(excel_file) # 使用 pandas 读取 Excel 文件
+
+ # 遍历 DataFrame,将每个学生保存到数据库
+ for _, row in df.iterrows():
+ student_id = row['student_id']
+ name = row['name']
+ Student.objects.get_or_create(student_id=student_id, name=name) # 如果学生已存在则不创建
+
+ return redirect('roll_call') # 完成后重定向到点名页面
+ else:
+ form = UploadFileForm()
+
+ return render(request, 'upload_students.html', {'form': form}) # 渲染上传页面
+
+# 开始点名的视图
+def roll_call(request):
+ students = Student.objects.all() # 获取所有学生
+ selected_student = None # 初始化被选中的学生
+
+ # 当教师点击“开始点名”按钮时
+ if request.method == 'POST' and 'start_roll_call' in request.POST:
+ # 设置权重:总分越高,被点名的概率越低
+ weights = [1 / (student.score + 1) for student in students] # 根据分数调整被点名概率
+ selected_student = random.choices(students, weights=weights, k=1)[0] # 随机选择一个学生
+ request.session['selected_student_id'] = selected_student.student_id # 存储被点名学生的ID到session中
+ return redirect('confirm_roll_call') # 跳转到确认点名页面
+
+ return render(request, 'roll_call.html', {'selected_student': selected_student}) # 渲染点名页面
+
+# 确认点名的视图
+def confirm_roll_call(request):
+ # 从 session 中获取被点名的学生
+ student_id = request.session.get('selected_student_id')
+ student = get_object_or_404(Student, student_id=student_id)
+
+ if request.method == 'POST':
+ # 学生是否到课
+ if 'attended' in request.POST: # 如果选择了到课
+ student.score += 1 # 到课加1分
+ student.attendance_count += 1 # 到课次数加1
+
+ # 处理是否准确重复问题
+ if request.POST['question_repeat'] == 'accurate':
+ student.score += 0.5 # 重复问题准确,加0.5分
+ else:
+ student.score -= 1 # 重复问题不准确,扣1分
+
+ # 处理回答问题的准确性(0-3分)
+ answer_accuracy = float(request.POST.get('answer_accuracy', 0))
+ student.score += answer_accuracy # 根据回答准确性加分
+ else:
+ student.score -= 5 # 未到课扣5分
+
+ student.save() # 保存更新后的学生信息
+ return redirect('roll_call') # 返回点名页面,进行下一轮点名
+
+ return render(request, 'confirm_roll_call.html', {'student': student}) # 渲染确认点名页面
\ No newline at end of file