Django's login_required decorator does not redirect to previous page
===

My problem in the short version:

I have added the `login_required` decorator to one of my views. If I enter the URL in the browser which executes this view, the browser correctly redirects to the URL that contains my login form if the user is not authenticated. However, the browser never redirects back to the previous page and I have no idea why this does not work. I have tried hundreds of things.

My problem in the long version:

I have a Django project with a single app, let's call it `my_app`. All the templates of my project reside in `templates/my_app/`. I have a template called `main.html` which contains several forms, among them my login form. With an additional `POST` parameter called `form-type`, I check which of the forms has been submitted. The code looks like this:

    def process_main_page_forms(request):
    
        if request.method == 'POST':
            if request.POST['form-type'] == u'login-form':
                template_context = _log_user_in(request)

            elif request.POST['form-type'] == u'registration-form':
                template_context = _register_user(request)

            elif request.POST['form-type'] == u'password-recovery-form':
                template_context = _recover_password(request)

        else:
            template_context = {
                'auth_form': AuthenticationForm(),
                'registration_form': RegistrationForm(),
                'password_recovery_form': EmailBaseForm()
            }

        return render(request, 'my_app/main.html', template_context) 

The function `_log_user_in()` looks like this:

    def _log_user_in(request):
    
        message = ''
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)

        if user is not None:
            if user.is_active:
                login(request, user)
            else:
                message = 'Your account has been disabled. ' \
                          'Please contact the administrator.'
        else:
            message = 'Your username and password didn\'t match. Please try again.'

        template_context = {
            'auth_form': AuthenticationForm(),
            'registration_form': RegistrationForm(),
            'password_recovery_form': EmailBaseForm(),
            'message': message,
    }

        return template_context

I also include the necessary `<input>` elements in the template, e.g. for the login form this is:

    <input type="hidden" name="form-type" value="login-form" />
    <input type="hidden" name="next" value="{{ next }}" />

The URL pattern for this view is:

    url(r'^$', process_main_page_forms, name='main-page')

My second view renders two forms for changing email address and password for an authenticated user. It looks like this:

    @login_required(login_url='/')
    def change_user_credentials(request):
        
        if request.method == 'POST':

            if request.POST['form-type'] == u'change-email-form':
                template_context = _change_email_address(request)

            elif request.POST['form-type'] == u'change-password-form':
                template_context = _change_password(request)

        else:
            template_context = {'change_email_form': ChangeEmailForm()}

        return render(request, 'my_app/user.html', template_context)

The URL pattern for this second view is:

    url(r'^account/$', change_user_credentials, name='user-page')

Whenever I access `/account/` when I'm not authenticated, I'm successfully redirected to the main page that contains the login form. The resulting URL is `http://127.0.0.1:8000/?next=/account/` that contains the necessary `next` parameter. However, when I log in my account, I'm still on the main page. I never get redirected to the user page, although I provided the necessary `next` parameter in the login form. It seems that this parameter is always empty, but I don't know why. I also don't have any other redirection calls in my code.

Can you help me solving this problem? Thank you very much in advance.