示例#1
0
def login_page(request):
    """
    Displays a login form and processes it on submission.
    """
    if request.method == 'POST':
        login_form = LoginForm(request.POST)
        
        if login_form.is_valid():
            credentials = {
                    'username': login_form.cleaned_data['username'],
                    'password': login_form.cleaned_data['password']
            }
            user = authenticate(**credentials)
            if user is not None:
                login(request,user)
                return redirect('/blog')
    else:
    
        login_form = LoginForm()
    
    return render(request,'mainpage/login.html',{'form': login_form})
示例#2
0
 def test_login_page_view_displays_login_form(self):
     response = login_page(HttpRequest())
     login_form = LoginForm()
     
     self.assertContains(response, login_form.as_p())