2
votes

Here is my views.py

views.py
def user_login(request):
    if request.method  == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username = username , password = password)
        if user:
            if user.is_active:
                login(request , user)
                return HttpResponseRedirect('/zdorovo/')
            else:
                return HttpResponse('You dont have an account with us')
        else:
            print "Invalid Login Details: {0} , {1}".format(username , password)
            return HttpResponse('Invalid Login Details ')

    else:
        render(request , 'zdorovo/login.html' , {})

authenticate , login , HttpResponse , HttpResponseRedirect have been imported correctly. I also took care of Indentation , so the error is not raising from that end. Please help me understand the error.

Here is my login.html

<body>
  <h1>Login</h1>
  <form id="login_id" method="post" action="/zdorovo/login/">
    {% csrf_token %}
    Username: <input type="text" name="username"  value=""/>
    <br/>
    Password: <input type="password" name="password" value=""/>
    <br/>
    <input type="submit" value="Login" />
  </form>
</body>

P.S.:- Update me if you need other scripts from my end.

1
use return in the last else conditionbadiya
Its working now thanks.PRATEEK
I will post it as an answer so that it might be helpful for others.badiya

1 Answers

3
votes

Your function doesn't return anything when it executes the last else condition you should add a return statements.

return render(request , 'zdorovo/login.html' , {})