Django 尝试注册用户时,ConnectionRefusedError位于/accounts/register/
伙计们。在我的网站上注册用户时,我会遇到这个错误。我是初学者。我也没有收到激活电子邮件。请参阅下面的代码。你面对过这样的问题吗?我怎样才能解决它?我试着用不同的方法,但没有任何帮助 在我的应用程序中的my utilities.py中Django 尝试注册用户时,ConnectionRefusedError位于/accounts/register/,django,user-registration,activation,connection-refused,Django,User Registration,Activation,Connection Refused,伙计们。在我的网站上注册用户时,我会遇到这个错误。我是初学者。我也没有收到激活电子邮件。请参阅下面的代码。你面对过这样的问题吗?我怎样才能解决它?我试着用不同的方法,但没有任何帮助 在我的应用程序中的my utilities.py中 from django.template.loader import render_to_string from django.core.signing import Signer from bboard.settings import ALLOWED_HOSTS
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)
in 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设置 调试的第一个好方法是将电子邮件后端切换到控制台: