让用户更改信息字段的 django 表单应该让他们更改用户名、电子邮件、姓名和姓氏,但它会显示他们的国籍、性别、应用得分和生日。
views.py
def profileedit_view(request):
if request.method== 'POST':
form= PerfilEditadoForm(request.POST, instance = request.user)
if form.is_valid():
form.save()
return redirect('login')
else:
form= PerfilEditadoForm(instance=request.user)
args= {'form': form}
return render(request, 'profileedit', args)
form = UsuarioForm(request.POST or None)
if form.is_valid():
form.save()
context = {
'form': form
}
return render(request, "profileedit.html", context)
forms.py
class PerfilEditadoForm(UserChangeForm):
class Meta:
model = User
fields= ('email', 'username', 'first_name', 'last_name')
profileedit.py
<form method="POST" action="#"> {% csrf_token %}
<p>
{{ form.as_ul }}
<button class="btn btn-primary py-1 px-2" type="submit" > Save </button>
</p>
</form>
烙印99
catspeake
相关分类