crwed 6 months ago
parent 80e9d7d982
commit fdb3965295

@ -1,5 +1,3 @@
# Generated by Django 3.2.13 on 2022-06-13 12:20
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion

@ -5,7 +5,7 @@
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<form action="#" class="form-inline"> <form action="#" class="form-inline">
<input type="text" class="form-control" name="key" id="key" placeholder="按姓名查找"> <input type="text" class="form-control" name="key" id="key" placeholder="按课程查找">
<input type="submit" class="btn btn-default" value="搜索"> <input type="submit" class="btn btn-default" value="搜索">
</form> </form>
</div> </div>

@ -13,22 +13,19 @@ def login(request):
return render(request, 'login.html', ) return render(request, 'login.html', )
if request.method == 'POST': if request.method == 'POST':
# 获取form表单参数
role = request.POST.get('role') role = request.POST.get('role')
username = request.POST.get('username') username = request.POST.get('username')
pwd = request.POST.get('pwd') pwd = request.POST.get('pwd')
# 验证身份,用户名,密码
if role == '0': # 如果身份是学生 if role == '0': # 如果身份是学生
# 从学生表中查询是否有匹配结果
result = models.StuInfo.objects.filter(username=username, password=pwd) result = models.StuInfo.objects.filter(username=username, password=pwd)
# 如果用户存在的话
if result.exists(): if result.exists():
# 重定向到学生主页把学生ID sid 传到前台页面
return redirect('student_index', sid=result.first().id) return redirect('student_index', sid=result.first().id)
else: else:
return HttpResponse('failed') return HttpResponse('failed')
elif role == '1':
elif role == '1': # 如果身份是管理员
result = models.AdminInfo.objects.filter(username=username, password=pwd) result = models.AdminInfo.objects.filter(username=username, password=pwd)
if result.exists(): if result.exists():
return redirect('/manage/homepage/') return redirect('/manage/homepage/')
@ -182,7 +179,7 @@ def student_index(request, sid):
student_id = request.POST.get('sid') student_id = request.POST.get('sid')
course_obj = models.CourseInfo.objects.get(pk=course_id) course_obj = models.CourseInfo.objects.get(pk=course_id)
student_obj = models.StuInfo.objects.get(pk=student_id) student_obj = models.StuInfo.objects.get(pk=student_id)
# 添加学生选课信息 # 添加选课信息
student_obj.course.add(course_obj) student_obj.course.add(course_obj)
return HttpResponse('success') return HttpResponse('success')

Loading…
Cancel
Save