Q:

Django - Redirect user to "next" parameter after successful login

In my code, I am currently using the @login_required decorator. As far as I know (and can see in the URL), this passes to my login view a next parameter holding the original page the user was on. 
After checking the user's credentials, I'm trying to redirect him to the original page, but I can't figure out how to do it. I'm sure this must be really straightforward, but I've been stuck on it for quite some time and I had to ask for help before throwing away my keyboard. 
My view code is as follows:
from django.contrib.auth import login as auth_login, authenticate

def login(request):
form_class = LoginForm

if request.method == 'POST':
    form = form_class(data=request.POST)
    if form.is_valid():
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(request, username=username, password=password)
        if user is not None:
            auth_login(request, user)
            return redirect(?????????)
        else:
            #Error message
return render(request, 'login.html', {'form':form_class})

A:

after you check for successful login, you just need to do something like:
next_url = request.GET.get('next')
if next_url:
    return HttpResponseRedirect(next_url)
else:
    return render(request, 'main/main.html')

