Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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>
</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!
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.