如何在django注册应用程序中禁用电子邮件激活?
如何在django注册应用程序中禁用电子邮件激活?您可以随时修改为: 或者您可以改为: 与其修改注册应用程序,不如直接激活用户: user.is_active=True user.save() profile.activation\u key=“已激活” profile.save() 在看了更多之后。。。我想你想要的是使用这两种解决方案。可能会在Dominic建议的更改之后添加上面的代码(尽管我建议使用signals,或者如果可能的话对表单进行子类化) 好的,最后回答:如何在django注册应用程序中禁用电子邮件激活?,django,Django,如何在django注册应用程序中禁用电子邮件激活?您可以随时修改为: 或者您可以改为: 与其修改注册应用程序,不如直接激活用户: user.is_active=True user.save() profile.activation\u key=“已激活” profile.save() 在看了更多之后。。。我想你想要的是使用这两种解决方案。可能会在Dominic建议的更改之后添加上面的代码(尽管我建议使用signals,或者如果可能的话对表单进行子类化) 好的,最后回答: new_user = R
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)
最好从根本上解决问题,而不是通过调用命令自动激活用户来包扎问题 将此方法添加到registration 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)
在django注册的当前tip版本中,有一个没有电子邮件的简单后端,您可以编写自己的后端来指定所需的工作流。有关文档,请参见此处 要使用没有电子邮件的简单URL,只需将URL.py更改为指向此后端,例如
(r'^accounts/', include('registration.backends.simple.urls')),
为什么不使用django注册附带的简单后端而不是默认后端呢
新的工作流程将是。。。
1.用户通过填写注册表来注册。
2.用户的帐户已创建并立即激活,无需中间确认或激活步骤。
3.新用户将立即登录
因此,在主URL.py上,您可以更改:
url(r'^accounts/', include('registration.backends.default.urls')),
到
我弄错了吗?我没有试过我的代码,只是看了一下django-registration中的代码。没有,我实际上只是编辑了我的答案,因为我认为我们的两种解决方案都是必要的:)这是怎么回事?你知道一种不修改django注册码的方法吗?我的想法就像一个信号,当用户被创建时,你需要调用activate_user,但是在新版本的django register中,file forms.py不喜欢这样。检查此链接:这在不修改代码的情况下非常简单。哦,快。我不知道这个答案有多旧…整个答案似乎都不推荐,包括所有链接和逻辑都在不同的位置。我按照您的过程进行操作,但当我输入用户时,它不会被激活。
(r'^accounts/', include('registration.backends.simple.urls')),
url(r'^accounts/', include('registration.backends.default.urls')),
url(r'^accounts/', include('registration.backends.simple.urls')),