简体   繁体   English

Django:PasswordResetForm 连接被拒绝

[英]Django : PasswordResetForm Connection refused

I used PasswordResetForm (code source by Django), but I have this error :我使用了 PasswordResetForm(Django 的代码源),但出现以下错误:

[Errno 111] Connection refused
...
/usr/lib/python2.7/socket.py in create_connection, line 571
...

My form PasswordResetForm : https://docs.djangoproject.com/fr/1.8/_modules/django/contrib/auth/forms/#PasswordResetForm我的表单 PasswordResetForm : https : //docs.djangoproject.com/fr/1.8/_modules/django/contrib/auth/forms/#PasswordResetForm

My view, idem ( https://docs.djangoproject.com/fr/1.8/_modules/django/contrib/auth/views/#password_reset ).我的观点,同上( https://docs.djangoproject.com/fr/1.8/_modules/django/contrib/auth/views/#password_reset )。

My urls :我的网址:

url(r'^parameters/password_reset','password_reset',name="password_reset"),
url(r'^parameters/password_reset_done','password_reset_done',name="password_reset_done"),
url(r'^parameters/password_reset_confirm','password_reset_confirm',name="password_reset_confirm"),
url(r'^parameters/password_reset_complete','password_reset_complete',name="password_reset_complete"),

and my settings :和我的设置:

#-*- coding: utf-8 -*-

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

#AUTHENTICATION_BACKENDS = ('backend.EmailAuthBackend',) Authentification : email+password

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
    'the_website',
    'bootstrapform',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
   )

   ROOT_URLCONF = 'the_website.urls'

   WSGI_APPLICATION = 'the_website.wsgi.application'


# Database

DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Internationalization

LANGUAGE_CODE = 'fr-FR'

TIME_ZONE = 'Europe/Paris'

USE_I18N = True

USE_L10N = True

USE_TZ = True


   # Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates'),
)

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

LOGIN_URL = '/the_website/'

When I test in the shell :当我在 shell 中测试时:

In [6]: send_mail("Test","Test","xxxx@yahoo.fr", ["yyyy@yahoo.fr"])
---------------------------------------------------------------------------
 error                                     Traceback (most recent call last)
 <ipython-input-6-0682cb627fb0> in <module>()
 ----> 1 send_mail("Test","Test","xxxx@yahoo.fr",["yyyy@yahoo.fr"])

 /usr/local/lib/python2.7/dist-packages/django/core/mail/__init__.pyc in send_mail(subject, message, from_email, recipient_list, fail_silently, auth_user, auth_password, connection, html_message)
 60         mail.attach_alternative(html_message, 'text/html')
 61 
---> 62     return mail.send()
     63 
     64 

/usr/local/lib/python2.7/dist-packages/django/core/mail/message.pyc in send(self, fail_silently)
281             # send to.
282             return 0
--> 283         return self.get_connection(fail_silently).send_messages([self])
284 
285     def attach(self, filename=None, content=None, mimetype=None):

     /usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.pyc in send_messages(self, email_messages)
 90             return
 91         with self._lock:
 ---> 92             new_conn_created = self.open()
 93             if not self.connection:
 94                 # We failed silently on open().

 /usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.pyc in open(self)
 48             connection_params['timeout'] = self.timeout
 49         try:
 ---> 50             self.connection = connection_class(self.host, self.port, **connection_params)
 51 
 52             # TLS/SSL are mutually exclusive, so only attempt TLS over

 /usr/lib/python2.7/smtplib.pyc in __init__(self, host, port, local_hostname, timeout)
254         self.esmtp_features = {}
255         if host:
--> 256             (code, msg) = self.connect(host, port)
257             if code != 220:
258                 raise SMTPConnectError(code, msg)

/usr/lib/python2.7/smtplib.pyc in connect(self, host, port)
314         if self.debuglevel > 0:
315             print>>stderr, 'connect:', (host, port)
--> 316         self.sock = self._get_socket(host, port, self.timeout)
317         (code, msg) = self.getreply()
318         if self.debuglevel > 0:

/usr/lib/python2.7/smtplib.pyc in _get_socket(self, host, port, timeout)
289         if self.debuglevel > 0:
290             print>>stderr, 'connect:', (host, port)
--> 291         return socket.create_connection((host, port), timeout)
292 
293     def connect(self, host='localhost', port=0):

/usr/lib/python2.7/socket.pyc in create_connection(address, timeout, source_address)
569 
570     if err is not None:
--> 571         raise err
572     else:
573         raise error("getaddrinfo returns an empty list")

error: [Errno 111] Connection refused

I know this was asked a while ago, but I think the same problem is still relevant.我知道这是不久前被问到的,但我认为同样的问题仍然相关。 All you need to do is add some email configuration to your settings.py.您需要做的就是在 settings.py 中添加一些电子邮件配置。 See the docs .请参阅文档 Add all of the following to settings.py:将以下所有内容添加到 settings.py:

 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = '<your smtp server>' EMAIL_HOST_PASSWORD = '<your smtp password>' EMAIL_HOST_USER = '<your smtp user email address>' EMAIL_HOST_PORT = <your smtp port>

If you haven't set up an email service, you can link your gmail account for free.如果您尚未设置电子邮件服务,则可以免费关联您的 Gmail 帐户。 Mandrill (smtp.mandrillapp.com) and Sendgrid are both good python-friendly resources as well. Mandrill (smtp.mandrillapp.com) 和 Sendgrid 也是很好的 Python 友好资源。

I also noticed that your setup is spread across forms.py, views.py, urls.py, and settings.py.我还注意到您的设置分布在 forms.py、views.py、urls.py 和 settings.py 中。 A more efficient setup can be found here .可以在此处找到更有效的设置。 It automatically configures views.py and urls.py--no need to add anything.它会自动配置 views.py 和 urls.py——无需添加任何内容。 Just make sure your forms.py and settings.py are filled out correctly, and you're golden!只要确保你的 forms.py 和 settings.py 填写正确,你就是金子!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM