AttributeError:"tuple"对象没有属性"encode"(Django联系表单) [英] AttributeError: 'tuple' object has no attribute 'encode' (django contact form)
问题描述
我正在为django项目创建一个联系"页面.forms.py具有名称,主题,发件人和消息.这是视图:
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})
模板:
<h1>Contact Us</h1>
<form method="POST">
{%csrf_token%}
{{form.as_p}}
<div class="form-actions">
<button type="submit">Send</button>
</div>
</form>
单击发送"后,出现以下错误:AttributeError:'tuple'对象没有属性'encode',尽管最近几天检查了相同类型的其他问题,我似乎也无法找出问题所在.我已经按照链接1 和
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!
推荐答案
如果有人遇到相同的问题,请检查您的settings.py文件.它可能带有结尾的逗号.这是我的问题.
If anyone ever faces the same issue, check your settings.py file. It might have trailing commas. This was the issue for me.
这篇关于AttributeError:"tuple"对象没有属性"encode"(Django联系表单)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!