diff --git a/pythonProject03/mysite10_7/polls/__pycache__/views.cpython-37.pyc b/pythonProject03/mysite10_7/polls/__pycache__/views.cpython-37.pyc index 4fc8fb7..91da5c4 100644 Binary files a/pythonProject03/mysite10_7/polls/__pycache__/views.cpython-37.pyc and b/pythonProject03/mysite10_7/polls/__pycache__/views.cpython-37.pyc differ diff --git a/pythonProject03/mysite10_7/polls/views.py b/pythonProject03/mysite10_7/polls/views.py index 2554132..e4997ac 100644 --- a/pythonProject03/mysite10_7/polls/views.py +++ b/pythonProject03/mysite10_7/polls/views.py @@ -64,10 +64,11 @@ def upload_students(request): return render(request, 'upload_students.html', {'form': form}) # 确保在GET请求时返回HttpResponse -@csrf_exempt # 如果需要,可以移除此装饰器,确保 CSRF 保护 +@csrf_exempt def roll_call(request): students = Student.objects.all() # 获取所有学生 + # 当教师点击“开始点名”按钮时 if request.method == 'POST': try: diff --git a/pythonProject03/mysite10_7/test/test_Login_view.py b/pythonProject03/mysite10_7/test/test_Login_view.py index e64a06a..d870159 100644 --- a/pythonProject03/mysite10_7/test/test_Login_view.py +++ b/pythonProject03/mysite10_7/test/test_Login_view.py @@ -1,18 +1,18 @@ import requests -# 目标 URL + url = 'http://127.0.0.1:8000/polls/index/' -# 测试数据 + data = { - 'user': 'zmm', # 用于测试的用户名 - 'pwd': 'Zmm' # 用于测试的密码 + 'user': 'zmm', + 'pwd': 'Zmm' } -# 发送 POST 请求 + response = requests.post(url, data=data) -# 检查响应状态和内容 +# if response.status_code == 200: print("登录成功:", response.json()) else: diff --git a/pythonProject03/mysite10_7/test/test_confirm_roll_call.py b/pythonProject03/mysite10_7/test/test_confirm_roll_call.py index a112bf6..4e70414 100644 --- a/pythonProject03/mysite10_7/test/test_confirm_roll_call.py +++ b/pythonProject03/mysite10_7/test/test_confirm_roll_call.py @@ -1,7 +1,7 @@ import requests import json -# 点名请求 + roll_call_url = 'http://127.0.0.1:8000/polls/roll_call/' roll_call_response = requests.post(roll_call_url, json={'start_roll_call': 'true'}) @@ -10,7 +10,7 @@ if roll_call_response.status_code == 200: selected_student_id = roll_call_response.json()['student_id'] - # 确认点名请求 + confirm_roll_call_url = 'http://127.0.0.1:8000/polls/confirm_roll_call/' confirm_data = { 'student_id': selected_student_id, diff --git a/pythonProject03/mysite10_7/test/test_leaderboard.py b/pythonProject03/mysite10_7/test/test_leaderboard.py index 1e73a6a..363ab15 100644 --- a/pythonProject03/mysite10_7/test/test_leaderboard.py +++ b/pythonProject03/mysite10_7/test/test_leaderboard.py @@ -1,12 +1,12 @@ import requests -# 设定接口 URL + leaderboard_url = 'http://127.0.0.1:8000/polls/leaderboard/' -# 发送 GET 请求 + response = requests.get(leaderboard_url) -# 检查请求是否成功 + if response.status_code == 200: print("排行榜数据:", response.json()) else: diff --git a/pythonProject03/mysite10_7/test/test_register.py b/pythonProject03/mysite10_7/test/test_register.py index 43e0a72..2d2b180 100644 --- a/pythonProject03/mysite10_7/test/test_register.py +++ b/pythonProject03/mysite10_7/test/test_register.py @@ -4,15 +4,15 @@ import json # 目标 URL url = 'http://127.0.0.1:8000/polls/register/' -# 发送 POST 请求,使用 json 参数而不是 data + data = { - 'user': 'zmm12300000', # 用于测试的用户名 - 'pwd': 'Zmm12314' # 用于测试的密码 + 'user': 'zmm12300000', + 'pwd': 'Zmm12314' } -response = requests.post(url, json=data) # 使用 json 参数发送数据 +response = requests.post(url, json=data) + -# 检查响应状态和内容 if response.status_code == 200: print("注册成功:", response.json()) else: diff --git a/pythonProject03/mysite10_7/test/test_roll_call.py b/pythonProject03/mysite10_7/test/test_roll_call.py index 7cb7513..15143c4 100644 --- a/pythonProject03/mysite10_7/test/test_roll_call.py +++ b/pythonProject03/mysite10_7/test/test_roll_call.py @@ -3,14 +3,14 @@ import requests # 目标 URL url = 'http://127.0.0.1:8000/polls/roll_call/' -# 发送 POST 请求,模拟教师点击“开始点名”按钮 + data = { - 'start_roll_call': 'true' # 发送一个模拟参数以触发点名功能 + 'start_roll_call': 'true' } -response = requests.post(url, json=data) # 使用 json 参数 +response = requests.post(url, json=data) + -# 检查响应状态和内容 if response.status_code == 200: try: print("点名成功:", response.json()) diff --git a/pythonProject03/mysite10_7/test/tset_upload_students.py b/pythonProject03/mysite10_7/test/tset_upload_students.py index aade882..887bee1 100644 --- a/pythonProject03/mysite10_7/test/tset_upload_students.py +++ b/pythonProject03/mysite10_7/test/tset_upload_students.py @@ -1,17 +1,13 @@ import requests -# 目标 URL -url = 'http://127.0.0.1:8000/polls/upload/' # 确保与 Django 开发服务器地址一致 +url = 'http://127.0.0.1:8000/polls/upload/' -# 准备要上传的 Excel 文件 files = { - 'file': open('D:/python20240709/pycharm/mingdan.xlsx', 'rb') # 替换为你的 Excel 文件路径 + 'file': open('D:/python20240709/pycharm/mingdan.xlsx', 'rb') } -# 发送 POST 请求 response = requests.post(url, files=files) -# 检查响应状态和内容 if response.status_code == 200: print("学生信息上传成功:", response.json()) else: