Errno 65尝试发送电子邮件时没有主机路线

时间:2015-12-29 19:34:04

标签: python django email

我正在使用django 1.8,因为这是一项要求。

有了这个应用程序,我正在建立一个书店项目。目前,唯一创建的应用是“商店”。现在,我正在尝试创建一个允许帐户注册的表单。此表单用于向用户输入的电子邮件发送电子邮件。该电子邮件的链接包含添加帐户激活码的网址。

直到发送电子邮件(当用户添加他们的信息并点击提交时。这就是错误发生的地方。

当我在表单上按提交时,我看到以下错误。我真的不知道这里发生了什么。我已经将django.contrib.auth添加到已安装的应用程序中,确保所有迁移都已发生,重新构建了尽可能多的URL,但仍然没有爱。

如果有人有任何建议,请告诉我。如果可能的话请向我解释,就像我五岁,因为这是我的第一个djano项目,我还在这里踩水。如果你可以将它与烧瓶联系起来,那也可能有所帮助。

提前非常感谢。

error at /accounts/register/
[Errno 65] No route to host
Request Method: POST
Request URL:    http://localhost:8000/accounts/register/
Django Version: 1.8
Exception Type: error
Exception Value:    
[Errno 65] No route to host
Exception Location:     /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py in create_connection, line 571
Python Executable:      /Users/MNickey/PycharmProjects/django_bookstore/venv/bin/python
Python Version: 2.7.9
Python Path:    
['/Users/MNickey/PycharmProjects/django_bookstore/Development/django_bookstore',         '/Users/MNickey/PycharmProjects/django_bookstore/venv/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
 '/Users/MNickey/PycharmProjects/django_bookstore/venv/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg',
 '/Users/MNickey/PycharmProjects/django_bookstore/venv/lib/python27.zip',
 '/Users/MNickey/PycharmProjects/django_bookstore/venv/lib/python2.7',
 '/Users/MNickey/PycharmProjects/django_bookstore/venv/lib/python2.7/plat-darwin',
 '/Users/MNickey/PycharmProjects/django_bookstore/venv/lib/python2.7/plat-mac',
 '/Users/MNickey/PycharmProjects/django_bookstore/venv/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/MNickey/PycharmProjects/django_bookstore/venv/lib/python2.7/lib-tk',
 '/Users/MNickey/PycharmProjects/django_bookstore/venv/lib/python2.7/lib-old',
 '/Users/MNickey/PycharmProjects/django_bookstore/venv/lib/python2.7/lib-dynload',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/MNickey/PycharmProjects/django_bookstore/venv/lib/python2.7/site-packages']
Server time:    Tue, 29 Dec 2015 02:10:12 +0000

Views.py:

from django.shortcuts import render
from .models import Book

def index(request):
    return render(request, 'template.html')

def store(request):
    count = Book.objects.all().count()
    context = {
        'count': count,
    }
    return render(request, 'store.html', context)

Urls.py:

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    # Examples:
    # url(r'^$', 'django_bookstore.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    # url(r'^$', 'store.views.index', name='index'),
    url(r'^store/', include('store.urls'), name='store'),
    url(r'^accounts/', include('registration.backends.default.urls')),
    url(r'^admin/', include(admin.site.urls)),
]

商店/ urls.py:

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.store, name='index'),
]

Settings.py(partial):

# Application definition
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites.requests',
    'registration',
    'store',
)

# Registration
ACCOUNT_ACTIVATION_DAYS = 7
REGISTRATION_AUTO_LOGIN = True
LOGIN_REDIRECT_URL = '/store/'

# Email Settings
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_HOST_USER = "mnickey@gmail.com"
EMAIL_HOST_PASSWORD = "password removed"
EMAIL_POST = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = "books@mysterybooks.com"

2 个答案:

答案 0 :(得分:1)

将settings.py中的EMAIL_POST = 587更改为EMAIL_PORT = 587。 进行此更改可以解决问题。所以是的,它是网络连接,因为网络正在做它应该做的事情。

答案 1 :(得分:0)

错误65(EHOSTUNREACH)的字面解释是没有到主机的网络路由。第一个问题:什么是主持人?您的问题是它正在尝试在发生错误时发送邮件。所以它可能是你的SMTP服务器主机。这定义在哪里?你能登录吗?

编辑:我误解了错误消息,抱歉:/