NeIT
NeIT

Reputation: 155

When I send a letter to the mail gives an error 'tuple' object has no attribute 'get'

I do so that after registration to the post office a letter is sent but it gives me an error

The letter arrives in the mail, but gives an error and should redirect to another url 'tuple' object has no attribute 'get'

my Traceback:

File "D:\Users\MAestro\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\exception.py" in inner 34. response = get_response(request)

File "D:\Users\MAestro\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\deprecation.py" in call 96. response = self.process_response(request, response)

File "D:\Users\MAestro\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\middleware\clickjacking.py" in process_response 26. if response.get('X-Frame-Options') is not None:

Exception Type: AttributeError at /register/ Exception Value: 'tuple' object has no attribute 'get'

Settings

EMAIL_HOST = 'smtp.mail.ru'
EMAIL_PORT = 2525
EMAIL_HOST_USER = "[email protected]"
EMAIL_HOST_PASSWORD = "labrador75"
EMAIL_USE_TLS = True

SERVER_EMAIL = EMAIL_HOST_USER
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

views.py

def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)

        username = request.POST['username']
        password1 = request.POST['password1']
        password2 = request.POST['password2']
        email = request.POST['email']

        context = {'form': form,
                   'username': username,
                   'password1': password1,
                   'password2': password2,
                   'email': email}

        if form.is_valid():
            form.save()

            return redirect('/loginNow/') , send_mail('Тема', 'Тело письма', settings.EMAIL_HOST_USER, [email])

    else:
        form = RegisterForm()
        context = {'form': form
                   }

    return render(request, 'registration/registred.html', context)

Upvotes: 0

Views: 161

Answers (1)

Nafees Anwar
Nafees Anwar

Reputation: 6598

You are returning a tuple here

return redirect('/loginNow/') , send_mail('Тема', 'Тело письма', settings.EMAIL_HOST_USER, [email])

two comma separated values in form of a, b means tuple in python which is a data structure. You should do

if form.is_valid():
    form.save()
    send_mail('Тема', 'Тело письма', settings.EMAIL_HOST_USER, [email])
    return redirect('/loginNow/')

Upvotes: 0

Related Questions