Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django SetPasswordForm doesn't render anything

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

This is what I got:

views.py

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

SetPasswordForm class needs user instance

form = SetPasswordForm(request.user)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading