title: Django after @login_required redirect to next
body: <p>I feel like this is an easy question and I'm just missing 1 small step. </p>
  
  <p>I want to do any number of the following (as the term in the next parameter):</p>
  
  <pre><code>[not signed in] -&gt; profile -&gt; login?next=/accounts/profile/ -&gt; auth -&gt; profile.
  [not signed in] -&gt; newsfeed -&gt; login?next=/newsfeed/` -&gt; auth -&gt; newsfeed.
  </code></pre>
  
  <p>Whereas I am currently going:</p>
  
  <pre><code>[not signed in] -&gt; profile -&gt; login?next=/accounts/profile/ -&gt; auth -&gt; loggedin
  [not signed in] -&gt; newsfeed -&gt; login?next=/newsfeed/ -&gt; auth -&gt; loggedin
  </code></pre>
  
  <p>I am looking to somehow pass the <code>next</code> parameter from a form on <code>login</code> to <code>auth</code> and have <code>auth</code> redirect to this parameter</p>
  
  <p>Currently I am trying in my <code>login.html</code>:</p>
  
  <pre><code>&lt;input type='text' name="next" value="{{ next }}"&gt;
  </code></pre>
  
  <p>however this is not getting the next value. I can see from the debug tool bar:</p>
  
  <pre><code>GET data
  Variable    Value
  u'next'     [u'/accounts/profile/']
  </code></pre>
  
  <p><code>views</code>:</p>
  
  <pre><code>def auth_view(request):
    username = request.POST.get('username', '')
    password = request.POST.get('password', '')
    user = auth.authenticate(username=username, password=password)
  
    if user is not None:
      auth.login(request, user)
      print request.POST
      return HttpResponseRedirect(request.POST.get('next'),'/accounts/loggedin')
    else:
      return HttpResponseRedirect('/accounts/invalid')
  </code></pre>
  
  <p><code>login.html</code>:</p>
  
  <pre><code>{% extends "base.html" %}
  
  {% block content %}
  
    {% if form.errors %}
    &lt;p class="error"&gt; Sorry, you have entered an incorrect username or password&lt;/p&gt;
    {% endif %}
    &lt;form action="/accounts/auth/" method="post"&gt;{% csrf_token %}
      &lt;label for="username"&gt;User name:&lt;/label&gt;
      &lt;input type="text" name="username" value="" id="username"&gt;
  
      &lt;label for="password"&gt;Password:&lt;/label&gt;
      &lt;input type="password" name="password" value="" id="password"&gt;
  
      &lt;input type='text' name="next" value="{{ request.GET.next }}"&gt;
      &lt;input type="submit" value="login"&gt;
    &lt;/form&gt;
  
  {% endblock %}
  </code></pre>
  
  <p><code>settings</code>:</p>
  
  <pre><code>from django.conf.urls import patterns, include, url
  
  from django.contrib import admin
  admin.autodiscover()
  
  urlpatterns = patterns('',
      # Examples:
  
      url(r'^admin/', include(admin.site.urls)),
      ('^accounts/', include('userprofile.urls')),
  
      url(r'^accounts/login/$', 'django_yunite.views.login'),
      url(r'^accounts/auth/$', 'django_yunite.views.auth_view'),
      url(r'^accounts/logout/$', 'django_yunite.views.logout'),
      url(r'^accounts/loggedin/$', 'django_yunite.views.loggedin'),
      url(r'^accounts/invalid/$', 'django_yunite.views.invalid_login'),
  
  )
  </code></pre>
  
  <p><code>settings</code>:</p>
  
  <pre><code># Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  import os
  BASE_DIR = os.path.dirname(os.path.dirname(__file__))
  
  # SECURITY WARNING: don't run with debug turned on in production!
  DEBUG = True
  
  TEMPLATE_DEBUG = True
  
  ALLOWED_HOSTS = []
  
  
  # Application definition
  
  INSTALLED_APPS = (
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'debug_toolbar',
      'userprofile',
  )
  
  MIDDLEWARE_CLASSES = (
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
  )
  
  ROOT_URLCONF = 'django_yunite.urls'
  
  WSGI_APPLICATION = 'django_yunite.wsgi.application'
  
  # Internationalization
  # https://docs.djangoproject.com/en/1.6/topics/i18n/
  
  LANGUAGE_CODE = 'en-ca'
  
  TIME_ZONE = 'EST'
  
  USE_I18N = True
  
  USE_L10N = True
  
  USE_TZ = True
  
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/1.6/howto/static-files/
  
  STATIC_URL = '/static/'
  
  STATICFILES_DIRS = (
      ('assets', '/home/user/GitHub/venv_yunite/django_yunite/static/'),
      )
  
  TEMPLATE_DIRS = (
      './templates',
      '/article/templates',
  )
  
  STATIC_ROOT = "/home/user/Documents/static/"
  
  AUTH_PROFILE_MODULE = 'userprofile.UserProfile'
  </code></pre>
  
  <p>the print statment shows an empty <code>u'next'</code></p>