Attributeerror: 'unicode' Object Has No Attribute 'get' - In Django Forms
Solution 1:
This part of the error says that data
is an unicode string:
returndata.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
Solution 2:
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.
Post a Comment for "Attributeerror: 'unicode' Object Has No Attribute 'get' - In Django Forms"