Home > front end >  Django SetPasswordForm doesn't render anything
Django SetPasswordForm doesn't render anything

Time:11-11

Django's SetPasswordForm doesn't render anything, please help.

This is what I got:

views.py

from django.contrib.auth.forms import SetPasswordForm

@login_required
def profile_security(request):
    template = "profiles/profile_security.html"
    form = SetPasswordForm
    print("form.base_fields: %s" % form.base_fields)
    context = {"profile_index_active": "active", "underline_security": "text-underline", "form": form}
    return render(request, template, context)

html

   <form method="post">{% csrf_token %}
         {{ form.as_p }}
   </form>

tried this html as well

            <form method="post">{% csrf_token %}
                <div class="form-group field-password1">
                    {{ form.new_password1.errors }}
                    <label for="id_new_password1">New Password</label>
                    {{ form.new_password1 }}
                </div>
                <div class="form-group field-password2">
                    {{ form.new_password2.errors }}
                    <label for="id_new_password2">Repeat New Password</label>
                    {{ form.new_password2 }}
                </div>
                <div class="form-group">
                    <input class="btn btn-success text-uppercase w-100" type="submit" value="Guardar nueva contraseña">
                </div>
            </form>

It does print the fields correctly:

form.base_fields: {'new_password1': <django.forms.fields.CharField object at 0x7f49174e2790>, 'new_password2': <django.forms.fields.CharField object at 0x7f49174e2940>}

but it doesn't render anything. What am I doing wrong?

CodePudding user response:

SetPasswordForm class needs user instance

form = SetPasswordForm(request.user)
  • Related