sixth commit

main
Lyanling 1 month ago
parent 05ad919fc8
commit 68697e557d

@ -64,10 +64,11 @@ def upload_students(request):
return render(request, 'upload_students.html', {'form': form}) # 确保在GET请求时返回HttpResponse return render(request, 'upload_students.html', {'form': form}) # 确保在GET请求时返回HttpResponse
@csrf_exempt # 如果需要,可以移除此装饰器,确保 CSRF 保护 @csrf_exempt
def roll_call(request): def roll_call(request):
students = Student.objects.all() # 获取所有学生 students = Student.objects.all() # 获取所有学生
# 当教师点击“开始点名”按钮时 # 当教师点击“开始点名”按钮时
if request.method == 'POST': if request.method == 'POST':
try: try:

@ -1,18 +1,18 @@
import requests import requests
# 目标 URL
url = 'http://127.0.0.1:8000/polls/index/' url = 'http://127.0.0.1:8000/polls/index/'
# 测试数据
data = { data = {
'user': 'zmm', # 用于测试的用户名 'user': 'zmm',
'pwd': 'Zmm' # 用于测试的密码 'pwd': 'Zmm'
} }
# 发送 POST 请求
response = requests.post(url, data=data) response = requests.post(url, data=data)
# 检查响应状态和内容 #
if response.status_code == 200: if response.status_code == 200:
print("登录成功:", response.json()) print("登录成功:", response.json())
else: else:

@ -1,7 +1,7 @@
import requests import requests
import json import json
# 点名请求
roll_call_url = 'http://127.0.0.1:8000/polls/roll_call/' 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'}) 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'] selected_student_id = roll_call_response.json()['student_id']
# 确认点名请求
confirm_roll_call_url = 'http://127.0.0.1:8000/polls/confirm_roll_call/' confirm_roll_call_url = 'http://127.0.0.1:8000/polls/confirm_roll_call/'
confirm_data = { confirm_data = {
'student_id': selected_student_id, 'student_id': selected_student_id,

@ -1,12 +1,12 @@
import requests import requests
# 设定接口 URL
leaderboard_url = 'http://127.0.0.1:8000/polls/leaderboard/' leaderboard_url = 'http://127.0.0.1:8000/polls/leaderboard/'
# 发送 GET 请求
response = requests.get(leaderboard_url) response = requests.get(leaderboard_url)
# 检查请求是否成功
if response.status_code == 200: if response.status_code == 200:
print("排行榜数据:", response.json()) print("排行榜数据:", response.json())
else: else:

@ -4,15 +4,15 @@ import json
# 目标 URL # 目标 URL
url = 'http://127.0.0.1:8000/polls/register/' url = 'http://127.0.0.1:8000/polls/register/'
# 发送 POST 请求,使用 json 参数而不是 data
data = { data = {
'user': 'zmm12300000', # 用于测试的用户名 'user': 'zmm12300000',
'pwd': 'Zmm12314' # 用于测试的密码 'pwd': 'Zmm12314'
} }
response = requests.post(url, json=data) # 使用 json 参数发送数据 response = requests.post(url, json=data)
# 检查响应状态和内容
if response.status_code == 200: if response.status_code == 200:
print("注册成功:", response.json()) print("注册成功:", response.json())
else: else:

@ -3,14 +3,14 @@ import requests
# 目标 URL # 目标 URL
url = 'http://127.0.0.1:8000/polls/roll_call/' url = 'http://127.0.0.1:8000/polls/roll_call/'
# 发送 POST 请求,模拟教师点击“开始点名”按钮
data = { 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: if response.status_code == 200:
try: try:
print("点名成功:", response.json()) print("点名成功:", response.json())

@ -1,17 +1,13 @@
import requests import requests
# 目标 URL url = 'http://127.0.0.1:8000/polls/upload/'
url = 'http://127.0.0.1:8000/polls/upload/' # 确保与 Django 开发服务器地址一致
# 准备要上传的 Excel 文件
files = { 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) response = requests.post(url, files=files)
# 检查响应状态和内容
if response.status_code == 200: if response.status_code == 200:
print("学生信息上传成功:", response.json()) print("学生信息上传成功:", response.json())
else: else:

Loading…
Cancel
Save