My project is working fine on my local machine but when I deploy it to my server I am getting an error
Exception Value: list index out of range
Exception Location: /var/www/bias_experiment/src/survey/views.py in get_context_data, line 151
As I said the project is working fine on my local machine. When I occasionally get this error I simply re-sync the DB which has always fixed it.
I have tried a number of things:
- Re-synced the DB on the server
python manage.py syncdb
- Restarted my server
sudo service apache2 restart
This had no effect so I
- Deleted my deployed project entirely
sudo rm -rf my_project
- Deleted the old DB
DROP DATABASE my_db_name
- Uploaded my project again
- Created a new DB
CREATE DATABASE my_db_name
- Synced it with the project 'python manage.py syncdb`
- Ran collectstatic
python manage.py collectstatic
- Ran
a2ensite
- Restarted my server
sudo service apache2 restart
However I am still getting the same error. I have no idea why the code works locally but breaks on my production server.
Any ideas? Thanks in advance
- Local machine: Python 2.7.5, Django 1.6.2
- Server: Ubuntu 12.4, Apache 2.2.22, Python 2.7.3, Django 1.6
EDIT: This is the offending code from views.py. Lines 128 - 156
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','11','12','13','14','15','16', '17']:
print '\nThe available list of Path_One images is', PATH_ONE_IMAGES
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
slider_value = self.request.POST.get('slider_value')
if slider_value is not None:
slider_DV_values.insert(step - 5, slider_value)
elif step == 8:
slider_value = self.request.POST.get('slider_value')
if slider_value is not None:
slider_DV_values.insert(step - 5, slider_value)
context['first_image'] = images[0]
context['second_image'] = images[1]
context['third_image'] = images[2]
context['first_slider'] = slider_DV_values[0]
context['second_slider'] = slider_DV_values[1]
context['third_slider'] = slider_DV_values[2]
elif step in (9, 10, 11):
image = random.choice(PATH_ONE_IMAGES)
images.insert(step - 6, image)
PATH_ONE_IMAGES.remove(image)
context['display_image'] = image
Thanks