I get this error:
Exception Type: IndexError at /institutes_admin/ Exception Value: list index out of range
Here are some details about the error:
Environment:
Request Method: GET Request URL: http://127.0.0.1:8000/institutes_admin/ Django Version: 1.1.1 Python Version: 2.6.5 Installed Applications: ['django.contrib.auth', 'django.contrib.admin', 'django.contrib.contenttypes', 'django.contrib.markup', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.comments', 'mysite.registration', 'mysite.profiles', 'mysite.epw', 'mysite.remember_me', 'mysite.avatar', 'mysite.django_documents', 'mysite.inlines', 'mysite.blog', 'mysite.forum', 'tagging'] Installed Middleware: ('django.middleware.cache.UpdateCacheMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.cache.FetchFromCacheMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'mysite.remember_me.views.AutoLogout')
Traceback: File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response 92. response = callback(request, *callback_args, **callback_kwargs) File "/usr/lib/pymodules/python2.6/django/utils/decorators.py" in _wrapped_view 48. response = view_func(request, *args, **kwargs) File "/home/karthik/Desktop/mysite/../mysite/epw/admin_views.py" in institutional_ip_admin 614. arranged_list = arrange_ips(chk_exist_obj) File "/home/karthik/Desktop/mysite/../mysite/epw/admin_views.py" in arrange_ips 582. total_value += (map_range(institute_obj, index), ) File "/home/karthik/Desktop/mysite/../mysite/epw/admin_views.py" in map_range 558. ip_value = ip_list_read(institute_obj, list_value, index) File "/home/karthik/Desktop/mysite/../mysite/epw/admin_views.py" in ip_list_read 548. ip_value.append(str(object_persistance(getattr(institute_obj, list_value + str(i)))[index-1]))
Exception Type: IndexError at /institutes_admin/ Exception Value: list index out of range
module I am working on:
def institutional_ip_admin(request, form_class = Institutional_Subscription_Form,temp开发者_运维知识库late_name
= "institutional_subscription.html"):
current_user = request.user
super_user, admin_user, dict_user = chk_admin_user(current_user)
if (super_user and admin_user) or (not super_user):
return HttpResponseRedirect("/admin_access/")
update_user_id = request.session['update_user_id']
result_of_update, result_of_category, result_of_cover, result_of_latest, result_of_block, result_of_footer, result_of_research = common_blocks()
ip_type = request.POST.get('ip_type')
update_user = User.objects.get(id = update_user_id)
chk_exist_obj = institutional_subscription.objects.filter(user__id=update_user_id).order_by('-id')
redirect_location = '/success/update_subscription/'
arranged_list = []
if chk_exist_obj:
chk_exist_obj = chk_exist_obj[0]
ip_type = chk_exist_obj.ip_type
arranged_list = arrange_ips(chk_exist_obj)
print arranged_list
if request.method == "POST":
form = form_class(data=request.POST)
if request.POST.get('ip_type') == 'edit':
data_dict = map_ip_attrs(request.POST)
result_dict = ip_seperate(data_dict, chk_exist_obj.ip_type)
chk_exist_obj.from1 = str(result_dict['from1'])
chk_exist_obj.from2 = str(result_dict['from2'])
chk_exist_obj.from3 = str(result_dict['from3'])
chk_exist_obj.from4 = str(result_dict['from4'])
chk_exist_obj.to1 = str(result_dict['to1'])
chk_exist_obj.to2 = str(result_dict['to2'])
chk_exist_obj.to3 = str(result_dict['to3'])
chk_exist_obj.to4 = str(result_dict['to4'])
chk_exist_obj.access_limit = request.POST.get('access_limit')
chk_exist_obj.save()
new_id = chk_exist_obj.id
old_user = chk_exist_obj.user
delete_old_records = institutional_subscription.objects.filter(user= old_user).exclude(id = new_id).delete()
return render_to_response('successful.html', {'user' : current_user, 'editsuccess':'Ips are updated successfully','result_of_update' : result_of_update, 'result_of_category' : result_of_category, 'result_of_cover' : result_of_cover, 'result_of_latest':result_of_latest, 'result_of_block' : result_of_block, 'result_of_footer':result_of_footer, 'result_of_research' : result_of_research, })
elif form.is_valid():
data_dict = form.cleaned_data
ip_type = request.POST.get('ip_type')
result_dict = ip_seperate(data_dict, ip_type)
ip_obj = institutional_subscription(
user = update_user,
from1 = str(result_dict['from1']),
from2 = str(result_dict['from2']),
from3 = str(result_dict['from3']),
from4 = str(result_dict['from4']),
to1 = str(result_dict['to1']),
to2 = str(result_dict['to2']),
to3 = str(result_dict['to3']),
to4 = str(result_dict['to4']),
access_limit = request.POST.get('access_limit'),
ip_type = ip_type
)
ip_obj.save()
new_id = ip_obj.id
old_user = update_user
delete_old_records = institutional_subscription.objects.filter(user = old_user).exclude(id = new_id).delete()
return render_to_response('successful.html', {'user' : current_user, 'editsuccess':'Ips are updated successfully','result_of_update' : result_of_update, 'result_of_category' : result_of_category, 'result_of_cover' : result_of_cover, 'result_of_latest':result_of_latest, 'result_of_block' : result_of_block, 'result_of_footer':result_of_footer, 'result_of_research' : result_of_research, })
else:
form = form_class()
pageinfo = "SubscriptionInstituteIpRange"
return render_to_response(template_name, {'user' : current_user, 'form' : form, 'result_of_category':result_of_category, 'result_of_update' : result_of_update, 'result_of_category' : result_of_category, 'result_of_cover' : result_of_cover, 'result_of_latest':result_of_latest, 'result_of_block' : result_of_block, 'result_of_footer':result_of_footer, 'result_of_research' : result_of_research, 'chk_exist_obj' : chk_exist_obj, 'arranged_list' : arranged_list, 'super_user' : super_user, 'redirect_location' : redirect_location})
I have seen your error (as requested), and it's not pretty. However, I can offer you two comments:
You should format it better to make it clearer. For the multi-line trackback, you'll want to format it using blockquotes. select the text, then click on the IOIO icon (or press Ctrl K).
« click that after selecting your pasted code!!
Your problem seems to be in your
ip_list_read
function inadmin_view.py
line548
. Perhapsindex-1
is larger than the actual size of the list returned byobject_persistence(...)
?
Of course, this is all guesswork as I don't know what the rest of the function look like, or what you're trying to achieve.
Update
Somewhere within that pile of code you have something that looks like
if chk_exist_obj:
chk_exist_obj = chk_exist_obj[0]
ip_type = chk_exist_obj.ip_type
arranged_list = arrange_ips(chk_exist_obj)
print arranged_list
Your arrange_ips()
function is the one that's causing the problem. What exactly does it do? Based on the statement chk_exist_obj = chk_exist_obj[0]
, we see that chk_exist_obj
is now a single list item. What are you trying to arrange?
From the trackback printout, arrange_ips()
calls ip_list_read()
which fails on line 548
as it tries to access a list entry that does not exist.
精彩评论