用户名中的什么参数= request.data.get('用户名','0')

时间:2019-11-14 17:11:45

标签: django django-rest-framework request

django rest框架教程,其表达式如下:

React Native Environment Info:
    System:
      OS: macOS 10.15.1
      CPU: (4) x64 Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz
      Memory: 86.16 MB / 8.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 12.6.0 - /usr/local/bin/node
      Yarn: 1.17.3 - /usr/local/bin/yarn
      npm: 6.10.2 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    IDEs:
      Android Studio: 3.5 AI-191.8026.42.35.5791312
      Xcode: 11.2.1/11B53 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.10 => 0.59.10 
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-create-library: 3.1.2
      react-native-git-upgrade: 0.2.7

我的问题是参数“ 0”在此表达式中意味着什么?

2 个答案:

答案 0 :(得分:1)

如果存在,它将获取并值;如果密钥不存在,则返回“ 0”。 Description

答案 1 :(得分:1)

request.data是一个字典,因此get函数在python词典上的工作原理完全相同:

  

get(键[,默认])   如果key在字典中,则返回key的值,否则返回默认值。如果未指定default,则默认为None,因此此方法永远不会引发KeyError。

来自docs