django MultiValueDictKeyError error, how do I deal with it

前端 未结 7 2132
终归单人心
终归单人心 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:44

    First check if the request object have the 'is_private' key parameter. Most of the case's this MultiValueDictKeyError occurred for missing key in the dictionary-like request object. Because dictionary is an unordered key, value pair “associative memories” or “associative arrays”

    In another word. request.GET or request.POST is a dictionary-like object containing all request parameters. This is specific to Django.

    The method get() returns a value for the given key if key is in the dictionary. If key is not available then returns default value None.

    You can handle this error by putting :

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

提交回复
热议问题