python - Django 请求反序列化
问题描述
我正在尝试反序列化 request.body:
from django.contrib.auth.models import User
from django.http import HttpResponse, HttpRequest
from django.http import HttpResponseRedirect
from django.shortcuts import render
import json
def register(request):
if request.method == 'POST':
if len(request.body) > 0 and len(request.FILES) == 0:
data = json.loads(request.body)
我在最后一行得到了 JSONDecodeError 。Python 3.6.4(无需解码,应该接受字节),Django 2.0.7。当我尝试打印 request.body 时,我得到:
b'username=1&password=1&email=and%40gm.co&csrfmiddlewaretoken=1iv975vw86CmmcDQM7IbpWxKsRn3J0RguI4ek5qKmTSfnyCRmu3wy7tcG0f36Cmr'
如果可能有帮助,还可以输入(请求):
<class 'django.core.handlers.wsgi.WSGIRequest'>
我究竟做错了什么?
解决方案
推荐阅读
- django - AWS ec2 Nginx + Django 服务器在没有太多流量的情况下轻松达到 100% 的 CPU 利用率
- java - 如何使用 FilterInputStream 就地替换两个或多个占位符?
- reactjs - 为什么 React.memo 的 areEqual 参数没有被执行
- node.js - 如何将相同的请求重定向到快递上的另一台服务器?
- java - Spring Boot 是否创建 N 个线程来处理 N 个 API 请求?
- php - 如何从 3 个连接表中获取供应商名称
- java - 夸库斯大学
没有按照公认的方式工作? - tensorflow - 在 keras 中训练机器学习模型的 GPU 和 XLA_CPU 有什么区别?
- python - 将打印功能的输出重定向到文本并禁用它
- floating-point - 如何在Matlab中的浮点变量中删除不需要的零?