Skip to content

Instantly share code, notes, and snippets.

@ErickMwazonga
Last active December 14, 2017 15:46
Show Gist options
  • Save ErickMwazonga/4eb6037f0af61bc854c603c4a3fa5058 to your computer and use it in GitHub Desktop.
Save ErickMwazonga/4eb6037f0af61bc854c603c4a3fa5058 to your computer and use it in GitHub Desktop.
feedback_mail_admins.py
from django.core.mail import mail_admins
def feedback(request):
if request.method == 'POST':
f = FeedbackForm(request.POST)
if f.is_valid():
name = f.cleaned_data['name']
sender = f.cleaned_data['email']
subject = "You have a new Feedback from {}:{}".format(name, sender)
message = "Subject: {}\n\nMessage: {}".format(f.cleaned_data['subject'], f.cleaned_data['message'])
mail_admins(subject, message)
f.save()
return redirect('feedback')
else:
f = FeedbackForm()
return render(request, 'blog/feedback.html', {'form': f})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment