Когда я передаю instance1
в контексте, это дает ошибку 'User' object is not iterable
.Я хочу отобразить имя в шаблоне pk
.Пример http://localhost:8000/users/15/profile-update/
pk=15
def userProfileUpdate(request, pk):
if request.method == 'POST':
u_form = UserUpdateForm(request.POST, instance=User.objects.get(id=pk))
p_form = UserProfileForm(request.POST,
request.FILES,
instance=UserProfile.objects.get(user_id=pk))
if u_form.is_valid() and p_form.is_valid():
u_form.save()
p_form.save()
messages.success(request, 'Profile Updated!!!')
return redirect('users')
else:
instance1 = User.objects.get(id=pk)
u_form = UserUpdateForm(instance=User.objects.get(id=pk))
p_form = UserProfileForm(instance=UserProfile.objects.get(user_id=pk))
context ={
'object': instance1, # This is giving the error
'u_form': u_form,
'p_form': p_form
}
return render(request, 'users/userprofile.html', context)
TypeError at /users/15/profile-update/
'User' object is not iterable
Request Method: GET
Request URL: http://localhost:8000/users/15/profile-update/
Django Version: 2.1.4
Exception Type: TypeError
Exception Value:
'User' object is not iterable
Exception Location: /home/codism-7/.local/share/virtualenvs/django-njoxc1BQ/lib/python3.5/site-packages/django/template/defaulttags.py in render, line 165
Python Executable: /home/codism-7/.local/share/virtualenvs/django-njoxc1BQ/bin/python3
Python Version: 3.5.2