我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用django.contrib.auth.forms.UserChangeForm()。
def EditUser(request, slug=None): """ Editar usuario de forma simple. """ user = request.user if request.method == 'POST': form = UserChangeForm(request.POST, instance=user) if form.is_valid(): #Actualizar el objeto user = form.save() messages.success(request, 'Usuario actualizado exitosamente.', extra_tags='html_dante') return HttpResponseRedirect(reverse('home:listar_usuarios')) else: form = UserChangeForm(instance=user) context = { 'form': form, } return render(request, 'home/user_change.html', context)
def __init__(self, *args, **kwargs): super(UserChangeForm, self).__init__(*args, **kwargs) if 'username' in self.fields: del self.fields['username']