无法解决 - 列表索引必须是整数,而不是 stR语言 字典声明



我已经研究了几天了,似乎想不通。我得到以下错误:

TypeError: list indices must be integers, not str

这是堆叠竞赛:

Stacktrace (most recent call last): 
File "django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "django/contrib/auth/decorators.py", line 22, in _wrapped_view
    return view_func(request, *args, **kwargs)
File "locations/views.py", line 722, in servicerecords
    cur_loc = Location.objects.get(id=location_id)

urls.py

    url(r'^location/(?P<location_id>d+)/servicerecservicerecords/$', 'locations.views.servicerecords',
   name='location_servicerecords'),

这是正在运行的代码:

def servicerecords(request, location_id):
    RECORDS_PER_PAGE = 15
    modal_visible = False
    show_requests = 0
    cur_service_rec = None
    cur_service_request = None
    page=None
    service_request_page=None
    variables = {}
    if request.GET.get('show_requests', ''):
        show_requests = int(request.GET.get('show_requests'))
    if request.GET.get('page',''):
        page = request.GET.get('page')
        service_request_page = request.GET.get('page')
    cur_loc = Location.objects.get(id=location_id)
    variables['location'] = cur_loc
    variables['locid'] = location_id
    ....
    ....

我是不是错过了什么?有人能帮我吗?感谢

cur_loc = Location.objects.get(id=int(location_id))

不是最安全的方法。您应该检查它是否是整数蚂蚁捕获,如果不是等。但基本上它可以工作

我通过重新启动服务器解决了问题。我相信我的代码文件存在更深层次的问题。

谢谢你的帮助。

相关内容

最新更新