Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取错误:发生意外异常:django电子邮件中的templates/email.txt_Python_Django_Django Models_Django Rest Framework_Django Views - Fatal编程技术网

Python 获取错误:发生意外异常:django电子邮件中的templates/email.txt

Python 获取错误:发生意外异常:django电子邮件中的templates/email.txt,python,django,django-models,django-rest-framework,django-views,Python,Django,Django Models,Django Rest Framework,Django Views,当我试图发送HTML电子邮件时,出现错误:发生意外异常:templates/email.txt,有人能帮我解释为什么会出现此错误吗?这里我附上了我的全部代码 email.txt Click <a href="">here</a> to signup for the company 你能提供一些额外的信息,比如完整的回溯和完整的视图吗?根据您当前提供的代码,我无法重现错误。我已更新代码,代码行为异常除外,为exp:您正在捕获所有异常,并打印通用的一行,而不是完整的回溯。这

当我试图发送HTML电子邮件时,出现错误:
发生意外异常:templates/email.txt
,有人能帮我解释为什么会出现此错误吗?这里我附上了我的全部代码

email.txt

Click <a href="">here</a> to signup for the company

你能提供一些额外的信息,比如完整的回溯和完整的视图吗?根据您当前提供的代码,我无法重现错误。我已更新代码,代码行为
异常除外,为exp:
您正在捕获所有异常,并打印通用的一行,而不是完整的回溯。这不是一个好主意。尝试移除Try/catch块,看看回溯告诉您什么
Click <a href="">here</a> to signup for the company
def post(self, request):

    try:
        required_params = ['user_id', 'user_email']
        data = request.data
        if all(key in data for key in required_params):
            user_id = data['user_id']
            user_email = data['user_email']

            inviteuser_object = InviteUser()
            inviteuser_object.user_id = user_id
            inviteuser_object.email = user_email
            inviteuser_object.save()



            # Send Email
            subject = 'Invited to Trial Risk'
            msg_plain = render_to_string('templates/email.txt', {'user_id': user_id})
            msg_html = render_to_string('templates/email.html', {'user_id': user_id})
            send_mail(
                'Invited to Trial Risk',
                msg_plain,
                '****@gmail.com',
                [user_email],
                html_message=msg_html,
            )

            return Response({"success": True, "status": "Success"},
                            status=status.HTTP_201_CREATED)

        else:
            return Response(
                {"success": False, "error": "Required param(s) missing, Please include and retry again"},
                status=status.HTTP_400_BAD_REQUEST)

    except Exception as exp:
        print("Unexpected exception occurred: " + str(exp))
        return Response({"success": False, "error": "Unexpected error occurred, please report this to Admin"},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)