【问题标题】:TypeError, send_mail() missing 1 required positional argument: 'recipient_list'TypeError,send_mail() 缺少 1 个必需的位置参数:'recipient_list'
【发布时间】:2020-04-14 01:12:30
【问题描述】:

我添加了一个布尔值,以便前端的属性标题不可更改,但我收到此错误。

TypeError at /contacts/contact
send_mail() missing 1 required positional argument: 'recipient_list'
Request Method: POST
Request URL:    http://127.0.0.1:8000/contacts/contact
Django Version: 3.0.4
Exception Type: TypeError
Exception Value:    
send_mail() missing 1 required positional argument: 'recipient_list'

views.py

def contact(request):
        if request.method == 'POST':
            property_id = request.POST['property_id']
            if 'property' in request.POST:
                property = request.POST['property']
            else:
                property = False

            name = request.POST['name']
            email = request.POST['email']
            message = request.POST['message']
            realtor_email = request.POST['realtor_email']

            contact = Contact(property=property, property_id=property_id, name=name, message=message )

            contact.save()

            # Send Email
            send_mail(
                'Property Inquiry',
                'There has been an inquiry for' + property + 'Check it',
                ['m@gmail.com', 'j@gmail.com'],
                fail_silently=False
            )

settings.py

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '******@gmail.com'
EMAIL_HOST_PASSWORD = '*****'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

更新: 这段代码成功了

'There has been an inquiry for' + str(property) + 'Check it',

【问题讨论】:

  • 请提供minimal reproducible example,以及完整的错误信息。
  • 'Property Inquiry'后面少了一个逗号
  • 当你想将 str 与 boolean 连接时,你也应该将 boolean 转换为 str 就像 'There has been an inquiry for' + str(property) + 'Check it'
  • 当我尝试将布尔值转换为 str 时,我得到一个 'send_mail() 缺少 1 个必需的位置参数:'recipient_list'' 错误

标签: python django django-views


【解决方案1】:

send_mail 函数中缺少,,希望对您有所帮助。

【讨论】:

    【解决方案2】:

    第一个来自,[]中的第二个是邮件列表

            # Send Email
            send_mail(
                'Property Inquiry',
                'There has been an inquiry for' + property + 'Check it',
                'your_account@gmail.com',
                ['m@gmail.com','j@gmail.com'],
                fail_silently=False
            )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-06
      • 2019-06-25
      • 2013-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多