django, пожалуйста, посмотрите на ошибку индекса, которую я получаю, для получения и редактирования модуля ip admin для институтов и сохранения IP-адреса. - PullRequest
0 голосов
/ 24 ноября 2010

Среда:

Метод запроса: GET URL запроса: http://127.0.0.1:8000/institutes_admin/ Версия Django: 1.1.1 Версия Python: 2.6.5 Установленные приложения: ['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 '] Установленное промежуточное программное обеспечение: (' django.middleware.cache.UpdateCacheMiddleware ',' django.middleware.common.CommonMiddleware ',' django.middleware.cache.FetchFromCacheMiddleware ',' django.condleribions. django.contribware.SessionMiddleware ',' django.contrib.auth.middleware.AuthenticationMiddleware ',' mysite.remember_me.views.AutoLogout ')

Трассировка: файл "/usr/lib/pymodules/python2.6/django/core/handlers / base.py "в get_response 92. response = callback (request, * callback_args, ** callback_kwargs) Файл "/usr/lib/pymodules/python2.6/django/utils/decorators.py" в _wrapped_view 48. response = view_func (request, * args, ** kwargs) Файл "/ home / karthik / Desktop / mysite/../mysite/epw/admin_views.py "в институциональный_ip_admin 614. файлaged_list =range_ips (chk_exist_obj)" /home/karthik/Desktop/mysite/../mysite/epw/admin_views.py "в организационном_ip 582. total_value += (map_range (institute_obj, index),) Файл "/home/karthik/Desktop/mysite/../mysite/epw/admin_views.py" в map_range 558. ip_value = ip_list_read (institute_obj, list_value, index) Файл "/ home/karthik/Desktop/mysite/../mysite/epw/admin_views.py "в ip_list_read 548. ip_value.append (str (object_persistance (getattr (institute_obj, list_value + str (i)))) [index-1]))

Тип исключения: IndexError at / institutes_admin / Значение исключения: индекс списка выходит за пределы диапазона

модуль, с которым я работаю

def институционный_ip_admin (запрос, класс_класса = Institutional_Subscription_Form, template_name = "институциональный_су)bscription.html "): current_user = request.user super_user, admin_user, dict_user = chk_admin_user (current_user) if (super_user и admin_user) или (не super_user): вернуть HttpResponseRedirect (" / admin_access / "= update_user_id_ 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 /'ered_list = [] если chk_exist_obj: chk_exist_obj = chk_exist_obj [0] ip_type = chk_exist_obj_jpg_type_org_list_range__id_id_d_date_range__forged_ize__for__ize__for__ize__set_list_ist_ist_ist_ist_ist_ist_ist_id_id_id_ru_istist_id_id_id_ru_ru_де.method == "POST": form = form_class (data = request.POST), если 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_rj.['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_obr.to4(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 (пользователь = old_user) .exclude (id = new_id) .delete () return render_to_response ( 'successful.html', {'user': current_user, 'editsuccess': 'Ips обновлены успешно ',' 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 (пользователь = old_user) .exclude (id = new_id) .delete () return render_to_response ( 'successful.html', {'user': current_user, 'editsuccess': 'Ips обновлены успешно ',' 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,'aged_list ': упорядоченный список, 'super_user': super_user, 'redirect_location': redirect_location})

Blockquote

1 Ответ

2 голосов
/ 24 ноября 2010

Я видел вашу ошибку (по запросу), и это не красиво. Тем не менее, я могу предложить вам два комментария:

  1. Вы должны отформатировать его лучше, чтобы сделать его более понятным. Для многострочного трекбека вы захотите отформатировать его с помощью цитат. выделите текст, затем щелкните значок IOIO (или нажмите Ctrl K ).
    значок кода http://oi52.tinypic.com/2la4o60.jpg "щелкните по нему после выбора вставленного кода !!

  2. Похоже, ваша проблема в функции ip_list_read в строке admin_view.py 548. Возможно, index-1 больше, чем фактический размер списка, возвращаемого object_persistence(...)?

Конечно, это все догадки, так как я не знаю, как выглядят остальные функции или чего вы пытаетесь достичь.

Обновление

Где-то в этой куче кода есть нечто, похожее на

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 

Ваша arrange_ips() функция является причиной проблемы. Что именно это делает? Основываясь на выражении chk_exist_obj = chk_exist_obj[0], мы видим, что chk_exist_obj теперь является одним элементом списка. Что вы пытаетесь организовать?

Из распечатки трекбэка arrange_ips() вызывает ip_list_read(), который завершается с ошибкой в ​​строке 548, когда он пытается получить доступ к записи списка, которая не существует.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...