Django在提交电子邮件时显示方法对象不可下标 [英] Django is showing a method object is not subscriptable when submitting email

查看:43
本文介绍了Django在提交电子邮件时显示方法对象不可下标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,我希望允许用户与我们联系.因此,当我单击提交"按钮时,出现错误 'method'对象不可下标

I have a website and I would like to allow users to contact us. Thus, when I click on the submit button I am getting the error 'method' object is not subscriptable

以下是错误:

TypeError at /contact/
'method' object is not subscriptable
Request Method: POST
Request URL:    https://massiwatechnology.com/contact/
Django Version: 2.1.8
Exception Type: TypeError
Exception Value:    
'method' object is not subscriptable
Exception Location: /home/massiwat/mysite/pages/views.py in contact, line 347
Python Executable:  /home/massiwat/virtualenv/mysite/3.7/bin/python3.7
Python Version: 3.7.3
Python Path:    
['',
 '/opt/alt/python37/bin',
 '/home/massiwat/mysite',
 '/home/massiwat/virtualenv/mysite/3.7/lib64/python37.zip',
 '/home/massiwat/virtualenv/mysite/3.7/lib64/python3.7',
 '/home/massiwat/virtualenv/mysite/3.7/lib64/python3.7/lib-dynload',
 '/opt/alt/python37/lib64/python3.7',
 '/opt/alt/python37/lib/python3.7',
 '/home/massiwat/virtualenv/mysite/3.7/lib/python3.7/site-packages']
Server time:    Wed, 11 Mar 2020 09:12:21 +0000
#Contact view.py

def contact(request):
    submitted = False
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
          #  full_name=form.cleaned_data['Th']
            mail=request.POST.get['email']
            subject=request.POST.get['objet']
            msg=request.POST.get['message']
            send_mail(mail, subject, msg, settings.EMAIL_HOST_USER, ['med.abdillah@massiwatechnology.com'],fail_silently=False)

        return HttpResponseRedirect('/contact?submitted=True')
    else:
        form = ContactForm()
        if 'submitted' in request.GET:
            submitted = True
    return render(request, 'contact.html', {'form': form, 'submitted': submitted})

下面是ContactForm.py:

And bellow is the ContactForm.py:

class ContactForm(forms.Form):
    # nom_complet=forms.CharField(max_length=100, required=True)
    email=forms.EmailField(required=True)
    objet=forms.CharField(widget=forms.Textarea(
                        attrs={
                            "rows":1, "cols":80
                            }
                        ))
    message=forms.CharField(
                    widget=forms.Textarea(
                        attrs={
                            "class":"message two",
                            "rows":5,"cols":80
                            }
                        )
                    )

我还想知道发送专业电子邮件的配置是否正确.

I also would like to know if the configuration bellow for sending a professional email is correct, please.

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_HOST='mail.massiwatechnology.com'
EMAIL_PORT='465'
EMAIL_HOST_USER='med.abdillah@massiwatechnology.com'
EMAIL_USE_TLS=True
EMAIL_HOST_PASSWORD='mypassord'

请协助

推荐答案

问题在于以下几行:

        mail=request.POST.get['email']
        subject=request.POST.get['objet']
        msg=request.POST.get['message']

.get 是一个方法而不是列表,因此应这样调用:

.get is a method and not a list and should therefore be called like this:

        mail=request.POST.get('email')
        subject=request.POST.get('objet')
        msg=request.POST.get('message')

这篇关于Django在提交电子邮件时显示方法对象不可下标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆