I am having an issue with persisting data from one page to the next in a SessionWizardView on my production server. It works fine on my local machine but I kept getting an Exception Value: list index out of range
error when I tried to access the value of the list on a subsequent page.
As a result I am trying to use the get_cleared_data_for_step
method but with no success.
My current 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]
Current outcome
This is your first image None
This is your second image None
This is your third image None
Expected outcome (sample)
This is your first image P1D1.jpg
This is your second image P3D3.jpg
This is your third image P4D4.jpg
What am I doing wrong? I can find very little info on how to implement the get_cleaned_data_for_step
method online except for these two SO questions [1], [2] and going by these my implementation looks like it should work.
Any help with this would be hugely appreciated. Thanks
Deepend