简体   繁体   English

从Django用户模型创建表单

[英]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. 我正在尝试使用Django的内置用户模型和通用视图构建用于注册用户的表单。 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. 我尝试了form.password_confirmation和form.confirm_password,但是它们不起作用。 Can't find this documented anywhere. 在任何地方都找不到此文档。

Give a try to django-registration to register users. 尝试django-registration来注册用户。 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 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...). 我想你的意思是这个形式: http//code.djangoproject.com/browser/django/tags/releases/1.2.3/django/contrib/auth/forms.py#L10 - 在这种情况下你应该有两个密码字段: password1password2 (所以奇怪的是password适合你并产生纯文本字段......)。 But, as Carles Barrobés suggested, you better give a try to django-registration . 但是,正如CarlesBarrobés所建议的那样,您最好尝试django-registration

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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