django MultiValueDictKeyError error, how do I deal with it

前端 未结 7 2119
终归单人心
终归单人心 2020-11-22 11:14

I\'m trying to save a object to my database, but it\'s throwing a MultiValueDictKeyError error.

The problems lies within the form, the is_private<

7条回答
  •  一整个雨季
    2020-11-22 11:54

    Use the MultiValueDict's get method. This is also present on standard dicts and is a way to fetch a value while providing a default if it does not exist.

    is_private = request.POST.get('is_private', False)
    

    Generally,

    my_var = dict.get(, )
    

提交回复
热议问题