0

I have customize Django 1.5 (from djangoproject docs) authentication to login with email instead of username and its working perfect, but I am using Django-registration 1.0 to register users.

How do I remove the username field from django registration so users will only need to enter e-mail & password when registering.

Thank you all in advance. Yaniv M

4

3 回答 3

2

这应该让你开始。创建您自己的表单,它是 RegistrationForm 的子类。

在forms.py

from registration.forms import RegistrationForm

class MyRegistrationForm(RegistrationForm):

    # Override RegistrationForm
    def __init__(self, *args, **kwargs):
        super(RegistrationForm, self).__init__(*args, **kwargs)
        self.fields.pop('username')

在views.py

from registration.views import RegistrationView

from yourapp.forms import MyRegistrationForm


class MyRegistrationView(RegistrationView):
    form_class = MyRegistrationForm

在 urls.py

url(r'^accounts/register/$', MyRegistrationView.as_view(),
    name='registration'),
于 2013-11-15T06:37:37.413 回答
0

您可以基于默认创建自定义表单类并在视图RegistrationForm中使用该类。RegistrationView

于 2013-06-21T10:55:49.813 回答
0

照原样,这很复杂。你需要:

  • 应用此补丁,因为在 dr-1.0 中,models.py 假定您的用户模型有一个“用户名”字段
  • 通过复制/粘贴/编辑registration/backends/default/views.py来创建自己的“后端”
  • 复制/粘贴/编辑注册表以及从registration/forms.py
  • 大多数情况下,您无需修改​​即可使用注册视图
于 2013-10-28T20:34:45.330 回答