Django 版本:3.2.5 Python 版本:3.9.5 已安装的应用程序: ['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'store.apps.StoreConfig']
已安装的中间件: ['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
错误
Traceback (most recent call last):
File "C:\Users\BOLARINWA\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\BOLARINWA\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\BOLARINWA\websites\ecommerce\store\views.py", line 36, in updateItem
data = json.loads('request.body')
File "C:\Users\BOLARINWA\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\BOLARINWA\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\BOLARINWA\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
Exception Type: JSONDecodeError at /update_item/
Exception Value: Expecting value: line 1 column 1 (char 0)
答案 0 :(得分:0)
您将字符串 'request.body'
传递到 json.loads
中的 store/views.py
,您需要传递实际数据:
data = json.loads(request.body)