0
您好我正在使用python/Django,在我的第一页(索引)我正在调用存储过程来获取数据。错误“'DefaultConnectionProxy'对象在调用存储过程时没有属性'__getitem__'”
def index(request):
listOPT = []
Data = []
fluxState = settings.FLUX_MANAGER_STATE
if fluxState != True:
listOPT.append('FLUX AXEREAL : OFF')
cursor = connection['site'].cursor()
"""MS SQL CALL TO STORED PROCEDURE SP_webGET_RESUME_MVT_INIT_ACTIF """
cursor.execute("{CALL SP_webGET_RESUME_MVT_INIT_ACTIF}")
mouvements = cursor.fetchall()
cursor.close()
return render(request, 'index.html', locals())
但在执行我得到这个错误 “ 'DefaultConnectionProxy' 对象有没有属性 '的GetItem'”
回溯:
Environment:
Request Method: GET
Request URL: http://10.1.20.14:8084/gestion_mouvement/index
Django Version: 1.9.6
Python Version: 2.7.11
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Gestion_Mouvement']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'easy_pjax.middleware.UnpjaxMiddleware']
Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "E:\prog2\PJ1705-027_Automatisation_Silo1_Site_LADON\4-Developpement\Informatique\Web\Gestion_Mouvements\Gestion_Mouvements\Gestion_Mouvement\views.py" in index
26. cursor = connection['site'].cursor()
Exception Type: TypeError at /gestion_mouvement/index
Exception Value: 'DefaultConnectionProxy' object has no attribute '__getitem__'
关于如何解决此问题的任何想法?我看到一些人不得不在他们的模型中添加一些def __unicode__
,但它似乎不适用于我。
感谢您的解决方案,但它摆脱错误的,但它似乎应该包含查询结果列表mouvements是空的(存储过程是一个简单的选择) –
这是一个完全独立的问题,我无法帮助。 – Alasdair