1

我已经安装了 Userena 应用程序并运行它。我可以注册,但没有电子邮件发送出去。如果这有所作为,我将覆盖注册表单。我没有收到任何错误消息,我可以看到正在数据库中创建用户。

设置.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'

表格.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

视图.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
4

1 回答 1

1

电子邮件未发送,因为您将电子邮件后端设置为虚拟后端

顾名思义,虚拟后端对您的消息没有任何作用

改变

django.core.mail.backends.dummy.EmailBackend

SMTP 后端

django.core.mail.backends.smtp.EmailBackend

另外,请确保

EMAIL_HOST_USER = 'email@gmail.com'
EMAIL_HOST_PASSWORD = 'password'

是有效收件箱的凭据

于 2013-07-22T02:57:32.857 回答