python - django python 中(POST 方法)处的 EncodeError。回复后 500
问题描述
我在下面有我的 python 类。我的问题是这个错误实际上意味着 /api/v1/jobs/apply/ > 的 EncodeError 不是 JSON 可序列化的。根据我下面的代码,它试图指出什么?谁能给个主意?. new_email 也在下面。
def new_application(self, data): 尝试:
def new_application(self, data):
try:
html = render_to_string("email_templates/new_application.tpl",data)
name = "testt"
data["subject"] = "test"
if env == "localhost":
msg = EmailMessage(data["subject"], html, name, dev_emails)
msg.content_subtype = "html" # Main content is now text/html
msg.attach_file(data["resume"])
msg.send()
else:
msg = EmailMessage(data["subject"], html, name, [data["company_email"]])
msg.content_subtype = "html" # Main content is now text/html
msg.attach_file(data["resume"])
msg.send()
except Exception as e:
print(str(e))
错误
EncodeError at /api/v1/jobs/apply/
<bound method Email.new_application of <v1.lib.emails.Email object at 0x7f6cbe44e908>> is not JSON serializable
代码
class ApplyJob(APIView):
def email(self, data):
email_ins = Email()
c_task.delay(email_ins.new_application, data)
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAuthenticated,IsApplicant)
def post(self, request, format=None):
data = request.data
job_applicant_ser = JobApplicantSerializer(data=data)
applicant = get_applicant_ins(request)
if applicant.profile_completeness <= 60:
return Response("You have not complete filling up your profile yet. Please complete it atleast 80% and above percentage..", status=status.HTTP_400_BAD_REQUEST)
if not applicant.resume:
return Response("Sorry, Please upload your resume.", status=status.HTTP_400_BAD_REQUEST)
job = data.get("job" , None)
cover_letter = data.get("cover_letter", None)
if not cover_letter or cover_letter == "":
return Response("Sorry, please fill your cover letter.", status=status.HTTP_400_BAD_REQUEST)
apply_job_checker_ins = JobApplicant.objects.filter(job=job,applicant=applicant).count()
if apply_job_checker_ins > 0:
return Response("Sorry but you cant apply to this company, it appears that you have already applied.", status=status.HTTP_400_BAD_REQUEST)
if job:
job = JobModel.objects.get(pk=job)
else:
return Response("Sorry but there is a problem with the application, please refresh page.", status=status.HTTP_400_BAD_REQUEST)
if job_applicant_ser.is_valid(raise_exception=True):
job_applicants = job_applicant_ser.save(applicant=applicant,job=job)
data = {}
data["job"] = job_applicants.job.title
data["account_url"] = APP_URL+"/account/job_applicants"
data["email"] = job_applicants.job.company.user.email
data["resume"] = STATIC_ROOT+"/uploads/resume/"+str(job_applicants.applicant.resume)
data["company_email"] = job_applicants.job.company.user.email
self.email(data)
return Response("You have applied to the jo
湾。请确保您的线路始终处于打开状态。", status=status.HTTP_200_OK)
解决方案
推荐阅读
- python - 如何在游戏中添加简单图形以在屏幕上添加滚动文本?
- android - RuntimeException:无法启动活动错误膨胀类 ImageView 和 ImageButton
- laravel-excel - Laravel excel 导出队列和MultipleSheet
- python - 如何正确编写从单独的 json 文件中读取密钥的 python 函数
- highcharts - 我如何使用 highcharts 做到这一点,叠加两个系列与 yAixs 共享
- c# - Selenium C#单击登录后无法重定向
- python - 将数据框中的python中的两个列表与一列中添加的文件名和另一列中的内容相结合
- flutter - 如何让我的 DropdownButton 影响我的 TextFormField
- android-studio - 为什么我的数据库文件夹显示正在加载...?
- amazon-web-services - 从 docker-compose.yml 到 Dockerrun.aws.json