在/ en-us / schools / 1 / classroom / 1 / update /
的NoReverseMatch找不到带有参数'('',)'的'index'的反向。尝试了1种模式:['zh-cn / schools /(?P \ d +)/ index / $']
urls.py
url(r'^(?P<school_id>\d+)/index/$', views.index, name='index'),
url(r'^(?P<school_id>\d+)/classroom/(?P<classroom_id>\d+)/update/$',
views.ClassroomUpdateView.as_view(), name='classroom_update')
views.py
def index(request, school_id):
school = get_object_or_404(School, pk=school_id)
classroom = school.classroom_set.all()
student_count = school.student_set.count()
guardian_count = school.guardian_set.count()
employee_count = school.employee_set.count()
teacher_count = school.teacher_set.count()
context = {
'school': school,
'classroom': classroom,
'student_count': student_count,
'guardian_count': guardian_count,
'employee_count': employee_count,
'teacher_count': teacher_count,
}
return render(request, 'home/home.html', context)
class ClassroomUpdateView(UpdateView):
model = Classroom
fields = ('classroom', 'numeric_name', 'class_teacher', 'note',)
template_name = 'classrooms/classroom_update.html'
pk_url_kwarg = 'classroom_id'
context_object_name = 'classroom'
def form_valid(self, form):
classroom = form.save(commit=False)
classroom.save()
return redirect('classroom_list', school_id=classroom.school.pk)