如何在django-registration应用中禁用电子邮件激活?
(r'^accounts/', include('registration.backends.simple.urls')),
url(r'^accounts/', include('registration.backends.default.urls')),
to
url(r'^accounts/', include('registration.backends.simple.urls')),
最好在根源处解决问题,而不是通过调用命令自动激活用户来进行包扎。
将此方法添加到注册models.py中:
def create_active_user(self, username, email, password,
site):
"""
Create a new, active ``User``, generate a
``RegistrationProfile`` and email its activation key to the
``User``, returning the new ``User``.
"""
new_user = User.objects.create_user(username, email, password)
new_user.is_active = True
new_user.save()
registration_profile = self.create_profile(new_user)
return new_user
create_active_user = transaction.commit_on_success(create_active_user)
接下来,编辑registration/backend/defaults/init.py文件并找到register()方法。
将以下内容更改为调用您的新方法:
#new_user = RegistrationProfile.objects.create_inactive_user(username, email,
#password, site)
new_user = RegistrationProfile.objects.create_active_user(username, email,
password, site)
您可以随时修改这一行代码为:
new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
password=self.cleaned_data['password1'],
email=self.cleaned_data['email'],
profile_callback=profile_callback,
send_email = False)
或者您可以将这一行更改为:
def create_inactive_user(self, username, password, email,
send_email=False, profile_callback=None):
不要修改注册应用程序,为什么不像django-registration一样激活用户:
经过更深入的研究...我认为你想要使用两种解决方案。可能在Dominic建议的更改之后添加上述代码(尽管我建议使用信号或子类化表单)
好的最终答案:
new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
password=self.cleaned_data['password1'],
email=self.cleaned_data['email'],
profile_callback=profile_callback,
send_email = False)
RegistrationProfile.objects.activate_user(new_user.activation_key)