我在生产服务器上的SessionWizardView中将数据从一个页面保存到下一个页面时出现问题。它在我的本地计算机上工作正常,但当我尝试在后续页面上访问列表的值时,我一直收到Exception Value: list index out of range
错误。
因此,我尝试使用get_cleared_data_for_step
方法,但没有成功。
我当前的views.py
PATH_ONE_IMAGES = ['P1D1.jpg', 'P2D2.jpg', 'P3D3.jpg', 'P4D4.jpg', 'P5D5.jpg']
class SurveyWizardOne(SessionWizardView):
def get_context_data(self, form, **kwargs):
context = super(SurveyWizardOne, self).get_context_data(form, **kwargs)
if self.steps.current in ['5','6','7','8','9','10']:
step = int(self.steps.current)
if step in (5, 6, 7):
image = random.choice(PATH_ONE_IMAGES)
images.insert(step - 5, image)
PATH_ONE_IMAGES.remove(image)
context['display_image'] = image
elif step == 8:
images[0] = self.get_cleaned_data_for_step(5)
images[1] = self.get_cleaned_data_for_step(6)
images[2] = self.get_cleaned_data_for_step(7)
print 'This is your first image', images[0]
print 'This is your second image', images[1]
print 'This is your third image', images[2]
当前结果
This is your first image None
This is your second image None
This is your third image None
预期结果(样本)
This is your first image P1D1.jpg
This is your second image P3D3.jpg
This is your third image P4D4.jpg
我做错了什么?我可以找到关于如何在线实施get_cleaned_data_for_step
方法的信息很少,除了这两个SO问题[1],[2]并且通过这些我的实现看起来应该可行。
对此的任何帮助都将非常感激。感谢
Deepend