Prakhar Trivedi Prakhar Trivedi - 1 year ago 132
Python Question

From django.core.mail EmailMessage Goes into infinite loop

I have a simple ahref link in my Django Project :

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

And on clicking it,the requested URL is :

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

And the requested view is :

def some_view(request,some_id):

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

template = get_template('../templates/email_templates/success_mail.html')
c = Context({})
html = template.render(c)
subject = "Successfull."
email = EmailMessage(subject, html, to=[usermail],from_email='')
email.content_subtype = "html"
return HttpResponseRedirect(request.path)

My Problem is,After clicking the button,email is getting repeatedly sent to the user.And this goes into infinite loop.How to solve this problem??

Answer Source

You are redirecting to view itself on this line.

return HttpResponseRedirect(request.path)

Just change it to something else, other than request.path

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download