gpt4 book ai didi

python - 从 django.core.mail EmailMessage 进入死循环

转载 作者:太空宇宙 更新时间:2023-11-04 10:07:12 24 4
gpt4 key购买 nike

我的 Django 项目中有一个简单的 ahref 链接:

<a class=" btn btn-md" href="/someurl/{{ some_id }}/">Notify User</a>

点击它,请求的 URL 是:

url(r'^someurl/(?P<some_id>\w+)/$', login_required(some_view), name='some_view'),

请求的 View 是:

    def some_view(request,some_id):

schObj = SomeModel.objects.get(id = some_id)
user = schObj.user
usermail = user.email
name = user.fname + " " + user.lname

template = get_template('../templates/email_templates/success_mail.html')
c = Context({})
c.update({'some_id':some_id,'address':user.address})
c.update({"fullname":name})
html = template.render(c)
subject = "Successfull."
email = EmailMessage(subject, html, to=[usermail],from_email='some_mail@gmail.com')
email.content_subtype = "html"
email.send()
return HttpResponseRedirect(request.path)

我的问题是,点击按钮后,电子邮件被重复发送给用户。这进入了无限循环。如何解决这个问题??

最佳答案

您正在重定向以在此 View 中查看自身:

def some_view(request,some_id):

schObj = SomeModel.objects.get(id = some_id)
user = schObj.user
usermail = user.email
name = user.fname + " " + user.lname
....
....

return HttpResponseRedirect(request.path)

只需将其更改为除 request.path 之外的其他内容即可

关于python - 从 django.core.mail EmailMessage 进入死循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40394588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com