def register(request):
if request.method == 'POST':
#1,查数据库比较email有没有重复
request_data=request.body
print(type(request_data))
if request_data:
request_dict=json.loads(request_data)
报如下错误:
JSONDecodeError at /register/
Expecting value: line 1 column 1 (char 0)
Request Method: POST
Request URL: http://localhost:8000/register/
Django Version: 3.0
Exception Type: JSONDecodeError
Exception Value:
Expecting value: line 1 column 1 (char 0)
Exception Location: C:\ProgramData\Anaconda3\lib\json\decoder.py in raw_decode, line 357
Python Executable: C:\ProgramData\Anaconda3\python.exe
Python Version: 3.6.5
Python Path:
['G:\\python\\Shangshu',
'G:\\python\\Shangshu',
'C:\\ProgramData\\Anaconda3\\python36.zip',
'C:\\ProgramData\\Anaconda3\\DLLs',
'C:\\ProgramData\\Anaconda3\\lib',
'C:\\ProgramData\\Anaconda3',
'C:\\ProgramData\\Anaconda3\\lib\\site-packages',
'C:\\ProgramData\\Anaconda3\\lib\\site-packages\\win32',
'C:\\ProgramData\\Anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\ProgramData\\Anaconda3\\lib\\site-packages\\Pythonwin',
'D:\\PyCharm 2018.2.4\\helpers\\pycharm_matplotlib_backend']
Server time: Sun, 19 Apr 2020 14:28:59 +0000
django请求报错JSONDecodeError
第1个回答 2020-05-27
json.loads(request_data, strict=False)
第2个回答 2020-04-19
request.body数据格式不是json,检查发送的请求体内容