django MultiValueDictKeyError error, how do I deal with it

前端 未结 7 2123
终归单人心
终归单人心 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 12:02

    You get that because you're trying to get a key from a dictionary when it's not there. You need to test if it is in there first.

    try:

    is_private = 'is_private' in request.POST
    

    or

    is_private = 'is_private' in request.POST and request.POST['is_private']
    

    depending on the values you're using.

提交回复
热议问题