0

I have if condition in django view. In this, if condition first checks if variable is set/not empty and in second condition it checks the value in this variable.

if ( request.GET['customActionType'] != '' and request.GET['customActionType'] == 'group_action') :
    records['customActionStatus'] = 'OK'
    records['customActionMessage'] = 'Group action successfully has been completed. Well done!'

But when I am using these variables in if condition its giving me error.

MultiValueDictKeyError at /admin/help
"'customActionType'"
Dinesh Pundkar
  • 4,160
  • 1
  • 23
  • 37
Pankaj
  • 229
  • 5
  • 17
  • 2
    I think it is duplicate of [this](http://stackoverflow.com/a/5895670/6709516) – Abdulafaja Sep 07 '16 at 05:58
  • sorry did not get it – Pankaj Sep 07 '16 at 05:59
  • What do you see when you `print request.GET`? I think there is no key named `customActionType` in it. – Ozgur Vatansever Sep 07 '16 at 06:01
  • @ozgur I think yes, thats why first i have to check if variable is isset or not how can i replace not empty condition with isset condition – Pankaj Sep 07 '16 at 06:06
  • sorry i ah using isset keyword because i an php developer but recently i have started working in python – Pankaj Sep 07 '16 at 06:10
  • Print request.data and see from Front End side you have pass the parameter in GET method only OR Print request.GET and check is there key with name 'customActionType' may be you have not pass the same key in request. – Piyush S. Wanare Sep 07 '16 at 06:20

1 Answers1

1

As mentioned in comments your question is duplicate of django MultiValueDictKeyError error, how do i deal with it

But there are some improvements that can be done to your code

Change your code to

if request.GET.get('customActionType', '') == 'group_action':
    records['customActionStatus'] = 'OK'
    records['customActionMessage'] = 'Group action successfully has been completed. Well done!'

This way you won't have to do 2 checks

Community
  • 1
  • 1
Sardorbek Imomaliev
  • 14,861
  • 2
  • 51
  • 63