def login_view(request): # View that handles your login gauth = GAuthify(GAUTHIFY_API_KEY) #Instantiate GAuthify section_form = LoginForm() # Your login form if request.method == 'POST': section_form = LoginForm(request.POST) if section_form.is_valid(): #Login valid, here we'd usually log the user in user_obj = section_form.cleaned_data['user_obj'] user_id = str( # Grab users unique id try: # Try except block to get or create user depending on existing on gauthify gauth_user = gauth.get_user(user_id) except NotFoundError: gauth_user = gauth.create_user(user_id, user_obj.doc['email'], email=user_obj.doc['email']) request.session['user_id'] = user_id #Set the user_id in the session to match it later return redirect(gauth_user['ez_url']) #Redirect them to the ez_url #render view for form, errors, etc return render_to_response('registration/forms.html', { 'section_form': section_form,}, context_instance=RequestContext(request))