django-registration,提交表格后出错500

时间:2013-12-26 19:28:42

标签: python django django-registration

我正在尝试使用django-registration app制作注册表单。但是,当我提交注册表单时,我收到消息“服务器错误(500)”?请帮助我 - 我做错了什么?

模板/注册/ registration_form.html:

<form method="post" action="">{% csrf_token %}
    <dl class="register">
        {% for field in form %}
            <dt>{{ field.label_tag }}</dt>
            <dd class="clearfix">{{ field }}
                {% if field.help_text %}<div class="clearfix">{{ field.help_text }}</div>{% endif %}
                {% if field.errors %}<div class="myerrors clearfix">{{ field.errors }}</div>{% endif %}
            </dd>
        {% endfor %}
    </dl>
    <input type="submit" value="Register" / class="clearfix">
</form>

urls.py:

url(r'^accounts/', include('registration.backends.default.urls')),

我运行了smtp服务器来测试邮件发送:

python -m smtpd -n -c DebuggingServer localhost:1025

控制台上没有电子邮件信息

settings.py:

ACCOUNT_ACTIVATION_DAYS = 2 #
AUTH_USER_EMAIL_UNIQUE = True
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = 'info@google.ru'

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.admin',
    'registration',
)

我创建了模板:

1.activation_email_subject.txt
Activation – {{ site }}

2.activation_email.txt
Follow {{ site }}/accounts/activate/{{ activation_key }}/

3.activate.html
Activated. <a href="{% url auth_login %}">Login</a> to site.

4.activation_email_subject.txt
Activation – {{ site }}

5.login.html
...

6.activation_complete.html
    activation_complete

7.activation_email_subject.txt
    Activation – {{ site }}

8.registration_complete.html
    Complete

9.logout.html
...

回溯切换到复制并粘贴视图

/home/bo858585/.env/local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response

                            response = callback(request, *callback_args, **callback_kwargs)
    ...
▶ Local vars
/home/bo858585/.env/local/lib/python2.7/site-packages/django/views/generic/base.py in view
                return self.dispatch(request, *args, **kwargs)
    ...
▶ Local vars
/home/bo858585/.env/local/lib/python2.7/site-packages/registration/views.py in dispatch
            return super(RegistrationView, self).dispatch(request, *args, **kwargs)
    ...
▶ Local vars
/home/bo858585/.env/local/lib/python2.7/site-packages/django/views/generic/base.py in dispatch
            return handler(request, *args, **kwargs)
    ...
▶ Local vars
/home/bo858585/.env/local/lib/python2.7/site-packages/registration/views.py in post
            if form.is_valid():
    ...
▶ Local vars
/home/bo858585/.env/local/lib/python2.7/site-packages/django/forms/forms.py in is_valid
            return self.is_bound and not bool(self.errors)
    ...
▶ Local vars
/home/bo858585/.env/local/lib/python2.7/site-packages/django/forms/forms.py in _get_errors
                self.full_clean()
    ...
▶ Local vars
/home/bo858585/.env/local/lib/python2.7/site-packages/django/forms/forms.py in full_clean
            self._clean_fields()
    ...
▶ Local vars
/home/bo858585/.env/local/lib/python2.7/site-packages/django/forms/forms.py in _clean_fields
                        value = getattr(self, 'clean_%s' % name)()
    ...
▶ Local vars
/home/bo858585/.env/local/lib/python2.7/site-packages/registration/forms.py in clean_username
            existing = User.objects.filter(username__iexact=self.cleaned_data['username'])
    ...
▶ Local vars
/home/bo858585/.env/local/lib/python2.7/site-packages/django/db/models/manager.py in __get__
                self.model._meta.object_name, self.model._meta.swapped
    ...
▶ Local vars 

1 个答案:

答案 0 :(得分:0)

您似乎为自定义auth.User交换了默认users.User

如果您想将django-registration与自定义User类一起使用,您还需要使用自定义注册表单。来自the source code

  

请注意,所有这些表单都假定Django的默认绑定User   模型;因为表格不可能提前预测   如果需要自定义用户模型,则需要编写自己的表单   你正在使用自定义模型。

您需要重新实施自定义User的注册表单,并告知django-registration使用它(在注册视图中设置form_class属性)