创建views

task_tool/views.py


def teacher_index(request, user_id):
    user = User.objects.get(id=user_id)
    teacher = Teacher.objects.get(user=user)
    task_list = Task.objects.filter(creator=teacher).order_by('-create_date')[:10]
    context = {
        'task_list': task_list,
    }
    return render(request, 'task_tool/teacher_index.html', context)

该函数会根据用户请求中传递的参数user_id获取相应的数据,并且使用这些数据渲染模板页面‘task_tool/teacher_index.html’。
该页面位于task_tool/templates/task_tool/teacher_index.html

你可能感兴趣的:(创建views)