简体   繁体   中英

Creating form from Django user model

I am trying to build a form for registering a user - using Django's built in user model and using generic views. I can't figure out how to confirm a password.

<form action="."  method="post">
{% csrf_token  %}
{{ form.non_field_errors }}
    <p>
        {{ form.username.errors }}
        <label for="username">Username</label>
        {{ form.username }}
    </p>
    <p>
        {{ form.email.errors }}
        <label for="email">Email</label>
        {{ form.email }}
    </p>
    <p>
        {{ form.password.errors }}
        {{ form.password.label_tag }}
        {{ form.password }}
    </p>
<p><input type="submit" value="Submit" /></p>
</form>

So my problems are that it doesn't submit and I can't confirm the password. The password is also plain text instead of hidden but I'll fix that later.

I tried form.password_confirmation and form.confirm_password but they don't work. Can't find this documented anywhere.

Give a try to django-registration to register users. It is a very complete, reusable app for that purpose. I use it and I'm quite happy with it.

http://bitbucket.org/ubernostrum/django-registration

You have the full sources to check how it solves the password confirmation issue, etc.

This may not directly answer your question, but it will probably solve your registration needs and allow you to focus your coding energies elsewhere.

I guess you mean this form: http://code.djangoproject.com/browser/django/tags/releases/1.2.3/django/contrib/auth/forms.py#L10 - in which case you should have two password fields: password1 and password2 (so it's strange that password works for you and produces plain text field...). But, as Carles Barrobés suggested, you better give a try to django-registration .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM