处理password_reset表单时出现Django auth错误

时间:2015-10-05 08:30:51

标签: django django-authentication

在我的项目中,我需要允许用户重置并更改其密码。在 base.html 模板中,我有:

<div class='login-first-row'>
  <form action="{% url 'login' %}" method='POST' role='form'>
     {% csrf_token %}
        <div class='form-group'>
          <label for='username'>Username</label>
          <input class='form-control' id='username' name='username' placeholder='username' type='text'>
        </div>
        <div class='form-group'>
          <label for='password'>Password</label>
          <input class='form-control' id='password' name='password' placeholder='Password' type='password'>
        </div>
        <button class='btn btn-success' type='submit'>Go!</button>
        <p>
          If you forgot your password
          <a href="{% url 'password_reset' %}">Click here</a>
        </p>
      </form>
    </div>

用户可以通过点击链接 href =“{%url'password_reset'%}”来访问password_reset_form.html。 我的password_reset_form.html

 {% extends "base.html" %}
 {% block content %}

  <div class='container l-wrap'>
    <div class='row'>
      <div class='span12'>
        <div class='container'>
          <div class='row'>
            <div class='span12'>
              <div class='login-page'>


                <p> Reset password </p>

                    <form action="" method="post">{% csrf_token %}
                        {{ form.email.errors }}
                        <p>
                            <label for="id_email"> Email address</label> 
                            {{ form.email }} 
                            <input type="submit" value="Reset my password" />
                        </p>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
 {% endblock %}

问题是,当我发布电子邮件地址时,我收到以下错误:

 IOError at /accounts/password_reset/
 [Errno 32] Broken pipe
 Request Method:    POST
 Request URL:   http://192.168.33.10:8000/accounts/password_reset/
 Django Version:    1.7.8
 Exception Type:    IOError
 Exception Value:   
 [Errno 32] Broken pipe
 Exception Location:    /vagrant/.virtualenv/local/lib/python2.7/site-packages/django/core/mail/backends/console.py in write_message, line 23
  Python Executable:    /vagrant/.virtualenv/bin/python
 Python Version:    2.7.3
 Python Path:   
 ['/vagrant',
 '/vagrant/.virtualenv/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
 '/vagrant/.virtualenv/src/yadu/src',
 '/vagrant/.virtualenv/src/python-social-auth-master',
 '/vagrant/.virtualenv/src/django-timedeltafield',
 '/vagrant/.virtualenv/local/lib/python2.7/site-packages/xhtml2pdf-0.0.6-py2.7.egg',
 '/vagrant/.virtualenv/local/lib/python2.7/site-packages/PyPDF2-1.25.1-py2.7.egg',
 '/vagrant/.virtualenv/local/lib/python2.7/site-packages/html5lib-1.0b8-py2.7.egg',
 '/vagrant/.virtualenv/lib/python2.7',
 '/vagrant/.virtualenv/lib/python2.7/plat-linux2',
 '/vagrant/.virtualenv/lib/python2.7/lib-tk',
 '/vagrant/.virtualenv/lib/python2.7/lib-old',
 '/vagrant/.virtualenv/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/vagrant/.virtualenv/local/lib/python2.7/site-packages',
 '/vagrant']

根据文档,当我从password_reset_form模板提交表单时,应该调用'django.contrib.auth.views.password_reset'视图。我调试了一些'print'并验证了这种情况并没有发生。我不明白我的帖子请求在哪里。

的myapp / urls.py

 urlpatterns = patterns('',
 url(r'^$', index, name='index'),
url(r'^email-sent/$', mail_sent),
url('', include('social.apps.django_app.urls', namespace='social')),
url(r'^admin/', include(custom_admin.urls)),    
url(r'^accounts/', include('django.contrib.auth.urls')),
[...]
)

的myapp / setting.py

INSTALLED_APPS = (
'suit',
'suit_redactor',
'django.contrib.sites',
'django.contrib.flatpages',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

# FIXME: remove
'django.contrib.webdesign',

'django_extensions',

'pipeline',
'ajaximage',
'easy_maps',
'embed_video',
'yadu',

'import_export',
'social.apps.django_app.default',
'core.app',
'paypal.standard.ipn',
'payment',
'deal',
'help',# FIXME: move the flatpages part into application of its own
'django.contrib.admin',    

)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'yadu.middleware.Debug',
'social.apps.django_app.middleware.SocialAuthExceptionMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.request",
)

ROOT_URLCONF = 'core.urls'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

感谢您提供任何帮助。

1 个答案:

答案 0 :(得分:0)

Exception Location: /vagrant/.virtualenv/local/lib/python2.7/site-packages/django/core/mail/backends/console.py in write_message, line 23

看起来django无法与您的电子邮件后端通话。检查您的设置,然后尝试使用./manage.py shell发送消息。