当我尝试注册用户时,/ accounts / register /中的ConnectionRefusedError

问题描述

伙计们。当尝试在我的网站上重新注册用户时,我遇到此错误。我是初学者。我也没有收到激活邮件。请参见下面的代码。你有遇到这样的问题吗?我该如何解决?我尝试使用不同的方法,但无济于事。

在我的Utility.py文件

from django.template.loader import render_to_string
from django.core.signing import Signer
from bboard.settings import ALLOWED_HOSTS


signer = Signer()

def send_activation_notification(user):
    if ALLOWED_HOSTS:
        host = 'http://' + ALLOWED_HOSTS[0]
    else:
        host = 'http://localhost:8000'
    context = {'user':user,'host':host,'sign':signer.sign(user.username)}
    subject = render_to_string('email/activation_letter_subject.txt',context)
    body_text = render_to_string('email/activation_letter_body.txt',context)
    user.email_user(subject,body_text)

在views.py

    def user_activate(request,sign):
    try:
        username = signer.unsign(sign)
    except BadSignature:
        return render(request,'main/bad_signature.html')
    user = get_object_or_404(AdvUser,username=username)
    if user.is_activated:
        template = 'main/user_is_activated.html'
    else:
        template = 'main/activation_done.html'
        user.is_active = True
        user.is_activated = True
        user.save()
    return render(request,template)

在settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = 'webmaster@localhost'

ALLOWED_HOSTS = [
    '127.0.0.1',]

如果我需要提供其他任何东西,请告诉我。

我看到此错误

ConnectionRefusedError at /accounts/register/
[WinError 10061] No connection Could be made because the target machine 
actively refused it
Request Method: POST
Request URL:    http://127.0.0.1:8000/accounts/register/
Django Version: 3.1
Exception Type: ConnectionRefusedError
Exception Value:    
[WinError 10061] No connection Could be made because the target machine 
actively refused it
Exception Location: C:\Users\Syubebayev 
Madiyar\AppData\Local\Programs\Python\python38-32\lib\socket.py,line 796,in 
create_connection
Python Executable:  C:\Users\Syubebayev 
Madiyar\AppData\Local\Programs\Python\python38-32\python.exe
Python Version: 3.8.0
Python Path:    
['C:\\Users\\Syubebayev Madiyar\\Desktop\\доска объявлений - сайт\\bboard','C:\\Users\\Syubebayev '
 'Madiyar\\AppData\\Local\\Programs\\Python\\python38-32\\python38.zip','C:\\Users\\Syubebayev '
 'Madiyar\\AppData\\Local\\Programs\\Python\\python38-32\\DLLs','C:\\Users\\Syubebayev '
 'Madiyar\\AppData\\Local\\Programs\\Python\\python38-32\\lib','C:\\Users\\Syubebayev Madiyar\\AppData\\Local\\Programs\\Python\\python38- 
  32','C:\\Users\\Syubebayev '
 'Madiyar\\AppData\\Roaming\\Python\\python38\\site-packages','C:\\Users\\Syubebayev '
 'Madiyar\\AppData\\Local\\Programs\\Python\\python38-32\\lib\\site- 

包”, 'C:\ Users \ Syubebayev' 'Madiyar \ AppData \ Local \ Programs \ Python \ python38-32 \ lib \ site- 包\ win32', 'C:\ Users \ Syubebayev' 'Madiyar \ AppData \ Local \ Programs \ Python \ python38-32 \ lib \ site-packages \ win32 \ lib', 'C:\ Users \ Syubebayev' 'Madiyar \ AppData \ Local \ Programs \ Python \ python38-32 \ lib \ site- 包\ Pythonwin'] 服务器时间:2020年10月3日,星期六10:53:26 +0000

解决方法

检查本地主机上端口25上是否运行SMTP。如果没有,则需要使用有效的SMTP设置。

首先要进行调试的是将电子邮件后端切换到控制台:https://docs.djangoproject.com/en/3.1/topics/email/#console-backend

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...