簡體   English   中英

使用電子郵件作為django-registration的用戶名

[英]Using email as username with django-registration

我使用Django的注冊2.0.4( https://django-registration.readthedocs.org/en/2.0.4/https://github.com/ubernostrum/django-registration )使用Django 1.8,我試圖自定義注冊表單和應用程序本身。 雖然我可以自定義表單,但我仍然堅持使用電子郵件作為用戶名。

我不需要在Django的后端更改任何內容,因為簡單地刪除表單中的用戶名字段並在后端使用輸入的電子郵件作為用戶名就足夠了。

我已經找到了這個( Django-Registration:Email as username ),但它已經有幾年的歷史了,我還沒有設法讓它運行起來。

我將如何以正確的方式實現所述功能? 有沒有人用最近的版本解決了這個問題?

編輯:

因為我被問到代碼:沒有太多與此問題相關的問題,因為它不是代碼問題,而是關於如何擴展或更改django插件的問題。

但是,我目前的,無聊的, form.py ,因為它在我鏈接的鏈接中:

class MyCustomForm(forms.Form):
    email = Email(required=True)
    password1 = forms.CharField(widget=forms.PasswordInput(), label="Password")
    password2 = forms.CharField(widget=forms.PasswordInput(), label="Repeat your password")

    def clean_password(self):
        if self.data['password1'] != self.data['password2']:
            raise forms.ValidationError('Passwords are not the same')
        return self.data['password1']

urls.py

...
url(r'^accounts/register/$', RegistrationView.as_view(form_class=InsuranceForm), name='registration_register'),
url(r'^accounts/', include('registration.backends.hmac.urls')),
...

我使用自定義用戶模型完成了這項工作。

https://docs.djangoproject.com/en/1.10/topics/auth/customizing/#auth-custom-user

上面的文檔中有一個完整的示例,您將需要稍微修改以實現您的目標。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM