0

I am creating a login form and after filling up the information it is showing 'str' object has no attribute 'get' error views.py file:

from django.shortcuts import render,redirect
from django.contrib import messages
from django.contrib.auth.models import User, auth

# Create your views here.
def login(request):
    if request.method == 'POST':
        username= request.POST['username']
        password = request.POST['password']
        user = auth.authenticate(username=username,password=password)
        if user is not None:
           auth.login(request,user)
           return("home")
        else:
           messages.info(request,"invalid credentials")
           return redirect('login')

    else:
        return render(request,'buy/login.html')

1 Answer 1

1

The error is happening because of this line:

               return("home")

In order to return a string, you must use:

    from django.http import HttpResponse

And then,

               return HttpResponse("home")

However, maybe you wanted to redirect to a view called 'home', and mistakenly forgotten redirect.

In that case just correct your code to:

               return redirect("home")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.