【问题标题】:Problem with django rest framework APIview in pythonanywherepythonanywhere中django rest框架APIview的问题
【发布时间】:2022-08-14 23:03:01
【问题描述】:

我构建了一个 APIView 来处理登录。 我使用 post 方法发送电子邮件和密码,如下所示

class LoginApi(views.APIView):

permission_classes = (AllowAny,) # Adding permission to everyone

def post(self,request):
    email = request.data[\'email\']
    password = request.data[\'password\']
    ...

这在我自己的系统中有效,但是当将其推送到 pythonanywhere 时,request.data 的形状会像这样改变:

在我的系统中:

{\"email\":\"email\",\"password\":\"1234\"}

但在 pythonanywhere 中是:

<QueryDict: {\'_content_type\': [\'application/json\'], \'_content\': [\'{\"email\":\"email\",\"password\":\"1234\"}\\r\\n\']}>

我的 django 版本和 rest-framework 与 pythonanywhere 相同。 只是我的 python 版本是 3.10,但 pythonanywhere 是 3.9。但我不认为这是问题所在。

  • 您可以在本地和 PythonAnywhere 上比较 requests\' 标头吗?使用的解析器将由Content-Type 标头确定,如the docs
  • @caseneuve 是的,这就是问题所在。我会发布确切的问题。

标签: django django-rest-framework pythonanywhere


【解决方案1】:

实际上我发送了错误的解析器所以我在 server(this is parser docs) 中得到了错误的数据

【讨论】:

    猜你喜欢
    • 2016-06-20
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 2020-05-06
    • 2021-10-30
    • 1970-01-01
    • 1970-01-01
    • 2018-11-05
    相关资源
    最近更新 更多