def LoginRequest(request): if request.user.is_authenticated(): return HttpResponseRedirect('/profile/') if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] client = authenticate(username=username, password=password) if client is not None: login(request, client) return HttpResponseRedirect('/profile/') else: return render_to_response('photoapi/login.html', {'form': form}, context_instance=RequestContext(request)) else: return render_to_response('photoapi/login.html', {'form': form}, context_instance=RequestContext(request)) else: ''' user is not submitting the form, show the login form ''' form = LoginForm() context = {'form': form} return render_to_response('photoapi/login.html', context, context_instance=RequestContext(request))