guys. i face this error when try to regiter user in my web site. i am beginner. also i do not receive activation email. please see below code. Did you face such issue? How can i solve it? i tried to use different methods, but nothing helped.
in my utilities.py in my app
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)
in 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',
]
if i need to provide anything else, please let me know.
i see this error
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-
packages', 'C:\Users\Syubebayev ' 'Madiyar\AppData\Local\Programs\Python\Python38-32\lib\site- packages\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- packages\Pythonwin'] Server time: Sat, 03 Oct 2020 10:53:26 +0000
Check if there SMTP running on your localhost at port 25. If it's not, then you need to use a working SMTP settings.
Good first for debugging would be to switch email back end to Console: https://docs.djangoproject.com/en/3.1/topics/email/#console-backend