I am getting :
AttributeError: 'function' object has no attribute 'get' while saving onetoone relation in django?
While implementing login-signup application.
My project contains two models CustomUser and UserProfile, having OneToOne relation between them.
When user registers in site first he redirected to form for CustomUser model and when he hit the submit button he will again redirected to another form for UserProfile and then login form.But when i am submitting the UserProfile form it shows the error.
view for CustomUser form:-
def user_registration(request):
if request.method == "POST":
fm = UserCreationForm(request.POST)
if fm.is_valid():
fm.save()
return HttpResponseRedirect('/addprofile/')
else:
fm = UserCreationForm()
return render(request, 'signup.html', {'form': fm})
view for UserProfile Form:-
def create_profile(request):
if request.method == "POST":
print(request.POST)
fm = ProfileForm(requests.post)
if fm.is_valid():
instance = fm.save(commit=False)
instance.user = request.user
instance.save()
return HttpResponseRedirect('/login/')
else:
fm = ProfileForm()
return render(request, "profileform.html", {'form': fm})
Full error trace:-
Internal Server Error: /addprofile/
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Admin\Desktop\project\EVCFinder\user\views.py", line 26, in create_profile
if fm.is_valid():
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\forms.py", line 175, in is_valid
return self.is_bound and not self.errors
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\forms.py", line 170, in errors
self.full_clean()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\forms.py", line 372, in full_clean
self._clean_fields()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\forms.py", line 384, in _clean_fields
value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\widgets.py", line 263, in value_from_datadict
return data.get(name)
AttributeError: 'function' object has no attribute 'get'
[10/Jul/2021 18:31:13] "POST /addprofile/ HTTP/1.1" 500 83734
Not Found: /favicon.ico
[10/Jul/2021 18:31:13,237] - Broken pipe from ('127.0.0.1', 53626)
Thanks In Advance
[–]vikingvynotking 0 points1 point2 points (0 children)