我正在尝试在两个视图之间传递一个列表,并且目前正在使用会话变量来执行此操作。
def EnrollmentVerification(request):
session_enrollments = Enrollment.objects.filter(id__in=request.session["enrollments"])
if request.method == 'POST':
form = EnrollmentVerificationForm(request.POST)
if form.is_valid():
# doing stuff
else:
form = EnrollmentVerificationForm(initial={'enrollments': session_enrollments})
return render_to_response("cup/enrollment_verification.html", {'form': form, 's_enrollments': session_enrollments}, context_instance=RequestContext(request))
列表中的渲染s_enrollments
在模板中效果很好,但多选小部件为空。我也尝试过:
form = EnrollmentVerificationForm(initial={'enrollments': request.session["enrollments"]})
这两种方法都不会导致填充小部件,即使呈现为列表的相同数据也可以正常工作。我的想法可能在某个地方被扭曲了。有任何想法吗?