【发布时间】:2022-01-25 09:04:08
【问题描述】:
这是来自 print(request.POST)
<QueryDict: {'csrfmiddlewaretoken': ['2Tg4HgJ07qksb3hPUDWSQYueYOjYOkQcmzll9fnjbJ0GZHkWHdM8DtYqZB4uv3Fv'], 'username': ['boycececil'], 'password': ['password']}>
这是来自 print(request.POST.get('username'))
boycececil
如您所见,列表(来自 QueryDict 的值之一)-> 字符串(来自 get 函数),这很神奇!不是吗?
那么,有人知道发生了什么吗?
【问题讨论】:
-
docs.djangoproject.com/en/4.0/ref/request-response/…
a dictionary-like class customized to deal with multiple values for the same keydocs.djangoproject.com/en/4.0/ref/request-response/…Returns the value for the given key. If the key has more than one value, it returns the last value -
仅供参考,在 python 中,您可以使用 type() 来查看对象的类型,它是谁的子类。在这种情况下,打印 type(request.POST) 并打印“django.http.request.QueryDict”,您可以查看 django 文档以查看“QueryDict”是什么以及此类是否存在多态性。
标签: django