I am creating a Contact page for my django project. forms.py has name, subject, sender and message. Here's the view:
def contact(request):
if request.method == 'GET':
form = ContactForm()
else:
form = ContactForm(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
sender_email = form.cleaned_data['sender_email']
subject = form.cleaned_data['subject']
message = form.cleaned_data['message']
send_mail(subject, message, sender_email, ['***@gmail.com'])
return render(request, 'contact_us.html', {'form': form})
The template:
<h1>Contact Us</h1>
<form method="POST">
{%csrf_token%}
{{form.as_p}}
<div class="form-actions">
<button type="submit">Send</button>
</div>
</form>
After I click Send I get this error: AttributeError: 'tuple' object has no attribute 'encode' and I can't seem to figure out what's wrong despite checking other questions of the same type the last couple of days.
I have followed instructions from link 1 and link 2 to set up the SMTP server (2 different cases) and it gives me the same error.
How can I fix that? Thank you!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…