如果自定義後端是在custom
文件夾,然後custom/forms.py
可能是這樣的:
from django import forms
from registration.forms import RegistrationForm
class RegistrationFormWithName(RegistrationForm):
first_name = forms.CharField(required=False)
last_name = forms.CharField(required=False)
這增加了你的兩個可選字段的默認登記表。要告訴您的自定義後端使用此新窗體而不是默認窗體,您需要更改custom/__init__.py
Muki's answer中的get_form_class
方法,說明如何做到這一點。
當然,您還需要處理保存來自first_name
和last_name
字段的數據。
編輯:
你custom/__init__.py
需求是這個樣子:
from registration.backends.default import DefaultBackend
from registration.backends.custom.forms import RegistrationFormWithName
class CustomBackend(DefaultBackend):
def get_form_class(self, request):
return RegistrationFormWithName
而且custom/urls.py
需要這樣一行:
url(r'^register/$', register, {'backend': 'registration.backends.custom.CustomBackend'}, name='registration_register'),
更改CustomBackend
類的名稱在這兩個文件中,無論你打電話給你的新後端。
查看default backend source以瞭解其他可覆蓋的方法。希望有所幫助。
我迷路了。 從django的進口形式 從registration.forms導入RegistrationForm 類RegistrationFormWithName(RegistrationForm): 如first_name = forms.CharField(所需=假) 姓氏仍然可以看到,只有4個字段 custom.forms.py寄存器形式= forms.CharField(所需=假) 定製/ __ init.py__包括: 從registration.forms導入RegistrationForm 從registration.backends.custom.forms導入RegistrationForm 定製/ urls.py,我改變線作爲這樣: 網址(r '^ register/$',register,{'backend':'registration.backends.custom.DefaultBackend'},name ='registration_register'), –