[Answer]-AttributeError: 'unicode' object has no attribute 'get' – In Django Forms

0👍

It seems that a workaround is to construct the form in the view.

I’ve looked at tenths and hundreds of StackOverFlow posts and Google websites, and non seem to have my problem.

The method is to recreate the form when you get the POST data, since a form uses a dictionary as a constructor.

changeNameForm = changeChartNameForm({request.POST['changeNameForm'].split("=")[0]}):request.POST['changeNameForm'].split("=")[1]})

I know that request.POST[‘changeNameForm’] returns a string “chartName=someName”. I split the string with “=”, and I would get someName, and chartName. Hence I would put someName into a dictionary, with the key called chartName.

{'chartName':'someName'}

Hence the form is recreated with the post data and finally passes is_valid.

1👍

This part of the error says that data is an unicode string:

return data.get(name, None) AttributeError: 'unicode' object has no attribute 'get'

data needs to be an object. Instead, it is a string, and strings don’t have a get() method, and don’t have name attributes as the error trace back says.

Try going off of the Django Docs to properly call the AJAX:

https://docs.djangoproject.com/en/1.6/topics/class-based-views/generic-editing/#ajax-example

Leave a comment