我已经安装了Userena应用程序并让它运行。我可以注册,但没有发送电子邮件。如果这会产生影响,我会覆盖注册表单。我没有收到任何错误消息,我可以看到正在数据库中创建用户。
settings.py
EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'email@gmail.com'
EMAIL_HOST_PASSWORD = 'password'
forms.py
from django.utils.translation import ugettext_lazy as _
from userena.forms import SignupForm
from models import UserProfile, RefUserAge, RefUserReference, RefUserSport, RefUserView
from django.contrib.auth.models import User
class SignupFormExtra(SignupForm):
age_pick = forms.ModelChoiceField(queryset = RefUserAge.objects.all())
ref_pick = forms.ModelChoiceField(queryset = RefUserReference.objects.all())
sport_pick = forms.ModelChoiceField(queryset = RefUserSport.objects.all())
view_pick = forms.ModelChoiceField(queryset = RefUserView.objects.all())
first_name = forms.CharField(label=_(u'First name'), max_length=30, required=False)
last_name = forms.CharField(label=_(u'Last name'), max_length=30, required=False)
def __init__(self, *args, **kw):
super(SignupFormExtra, self).__init__(*args, **kw)
def save(self):
new_user = super(SignupFormExtra, self).save()
new_user_profile = new_user.get_profile()
new_user_profile
new_user_profile.first_name = self.cleaned_data['first_name']
new_user_profile.last_name = self.cleaned_data['last_name']
new_user_profile.age_pick = self.cleaned_data['age_pick']
new_user_profile.ref_pick = self.cleaned_data['ref_pick']
new_user_profile.sport_pick = self.cleaned_data['sport_pick']
new_user_profile.view_pick = self.cleaned_data['view_pick']
new_user_profile.save()
return new_user
views.py
from django.http import HttpResponse, HttpResponseRedirect
from models import UserProfile
from django.shortcuts import render_to_response, RequestContext
from forms import SignupFormExtra
from userena import views as userena_views
def signup_view(request):
form = SignupFormExtra()
response = userena_views.signup(request, signup_form=SignupFormExtra)
return response
答案 0 :(得分:1)
由于您的电子邮件后端设置为Dummy backend
,因此未发送电子邮件顾名思义,虚拟后端对您的消息没有任何作用
更改
django.core.mail.backends.dummy.EmailBackend
django.core.mail.backends.smtp.EmailBackend
另外,请确保
EMAIL_HOST_USER = 'email@gmail.com'
EMAIL_HOST_PASSWORD = 'password'
是有效收件箱的凭据