title: UnboundLocalError at /signin/ local variable 'user' referenced before assignment in Django
body: <h2>Function to let the user to login as follows=&gt;</h2>
  <hr />
  <p>Obviously this error pops:</p>
  <h2></h2>
  <pre><code>def login_view(request):
    if request.method == 'POST':
  
      username = request.POST['username']
      password = request.POST['password']
      user = authenticate(request, username=username, password =password  )
    if user is not None:
      login(request, user)
      return HttpResponseRedirect(reverse(&quot;index&quot;))
    elif user is None:
                        return render(request, &quot;covi/signin.html&quot;, {
              &quot;message&quot;: &quot;Invalid username and/or password.&quot;
          })
    else:
                        return render(request, &quot;covi/signin.html&quot;)                  
              
             
  </code></pre>