Код: Выделить всё
views.pyКод: Выделить всё
def profile(request):
if request.method == 'POST':
u_form = UserUpdateForm(request.POST, instance=request.user)
p_form = ProfileUpdateForm(request.POST, request.FILES, instance=request.user.profile)
if u_form.is_valid() and p_form.is_valid():
u_form.save()
p_form.save()
messages.success(request, f'Account has been updated')
return redirect('profile')
else:
u_form = UserUpdateForm(instance=request.user)
p_form = ProfileUpdateForm(instance=request.user.profile)
context = {
'u_form': u_form,
'p_form': p_form
}
return render(request, 'users/profile.html', context)
Код: Выделить всё
users/profile.htmlКод: Выделить всё
{{ user.username }}
{{ user.email }}
[img]{{ user.profile.image.url }}[/img]
{% csrf_token %}
{{ u_form }}
{{ p_form }}
Update profile
< р>Я ожидал, что {{user.username }} останется таким же, как в базе данных и как данные вошедшего в систему пользователя
Подробнее здесь: https://stackoverflow.com/questions/784 ... -user-name