title: Django @login_required 'next' incorrect redirect
body: <p>My problem is that <code>@login_required</code> redirects to root page instead of correct next path.
  <code>/accounts/login/?next=/main/setka/</code> redirects to <code>'/'</code> instead of <code>/main/setka/</code> after logging in.</p>
  
  <p>Could anybody assist me?</p>
  
  <p>The code:</p>
  
  <p>Head urls</p>
  
  <pre><code>url(r'^main/', include('main.urls')),   
  url(r'^accounts/',include('loginsystem.urls')),
  </code></pre>
  
  <p>loginsystem.urls</p>
  
  <pre><code>(r'^login/$', 'django.contrib.auth.views.login'),
  </code></pre>
  
  <p>/main/ urls.py</p>
  
  <pre><code>(r'^setka/$', views.setka),
  </code></pre>
  
  <p>my link to the corresponding view with the decorator at '/' homepage</p>
  
  <pre><code>&lt;li&gt;&lt;a href="/main/setka/"&gt;Setka&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>loginsystem.views</p>
  
  <pre><code>@login_required
  def setka(request):
      return render_to_response('main/setka.html')
  </code></pre>
  
  <p>login.html includes</p>
  
  <pre><code>    {% load staticfiles %}
  
  &lt;link rel="stylesheet" type="text/css" href="{% static 'accounts/style.css' %}" /&gt;
  
  {% if form.errors %}
  &lt;p class="error"&gt;Sorry invalid&lt;/p&gt;
  {% endif %}
  &lt;body&gt;
  &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="submit" value="login" /&gt;
  &lt;input type="hidden" name="next" value="{{next}}" /&gt;
  
  &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Url chain likes this: 'root/' -> root/accounts/login/?next=/main/setka/ -> '/' instead of 'root/main/setka/'</p>
  
  <p>Any suggestions would be much appreciated.</p>
  
  <p><strong>To be specific, I want to dynamically attach 'next' path to root address, but it does not attach 'next' path at all.</strong></p>