发送邮件时显示错误,例如:AttributeError:“ int”对象没有属性“ splitlines”

时间:2019-12-18 17:06:54

标签: python django django-models django-views

在发送邮件时显示错误,例如AttributeError:'int'对象没有属性'splitlines',可以解决此问题

views.py

from django.conf import settings
from django.core.mail import send_mail
from random import randint
def send_emails(request,email):
n = 8
range_start = 10**(n-1)
range_end = (10**n)-1
passgenarate = randint(range_start, range_end)
print passgenarate
password = make_password(passgenarate)
print password

updatepassword =  User.objects.filter(email=email).update(password=password)
subject = 'newpassword'
from_email = settings.EMAIL_HOST_USER
recipient_list = email
message = passgenarate
send_mail(subject, message,from_email,[recipient_list],
          fail_silently=False, auth_user=None, auth_password=None,
          connection=None, html_message=None)

1 个答案:

答案 0 :(得分:1)

也许message = passgenarate必须是str,而它是int。尝试message = str(passgenarate)