title: Django: HttpResponseRedirect not working
body: <p>I'm new at Python/Django and programming overall. I need help with HttpResponseRedirect as it's not working from my Login view. It does work from my main Views file but not the way I want it.</p>
  
  <p>Instead of redirecting to the desired page ('/'), I only see this on the same page: </p>
  
  <blockquote>
    <p>Content-Type: text/html; charset=utf-8 Location: /</p>
  </blockquote>
  
  <p>The user actually gets logged in but stay on the same page. So, if I manually go to the desired page, I will see that I am logged in.</p>
  
  <p>Here are the relevant pieces of code. I am using my own views everywhere. I'd like it this way for practice and better understanding.</p>
  
  <p>Urls.py</p>
  
  <pre><code>from django.conf.urls import patterns, include, url
  from django.conf.urls.static import static
  from django.contrib.staticfiles.urls import staticfiles_urlpatterns
  from django.contrib import admin
  from backend import settings
  admin.autodiscover()
  
  urlpatterns = patterns('',
      url(r'^login/', 'backend.views.login', name = 'login'),
      url(r'^logout/', 'backend.views.logout', name = 'logout'),
      url(r'^$', 'backend.views.dash', name = 'dash'),
      url(r'^admin/', include(admin.site.urls)),
  ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  
  urlpatterns += staticfiles_urlpatterns()
  </code></pre>
  
  <p>Views.py</p>
  
  <pre><code>from dashboard.dashviews import left, right, topright
  from authentication.authviews import LoginView, LogoutView
  from django.shortcuts import render
  from django.http import HttpResponseRedirect
  from django.contrib.auth.decorators import login_required
  
  @login_required(login_url='/login/')
  def dash(request):
      return render(request, 'dash_template.html', 
          {'left': left.dash_left(request), 
           'right': right.dash_right(), 
          'topright': topright.top_right(request)})
  
  def login(request):
      if not request.user.is_authenticated():
          return render(request, 'login.html', {'login': LoginView.login_view(request)})
      else:
          return HttpResponseRedirect('/')
  
  def logout(request):
      return render(request, 'logout.html', {'logout': LogoutView.logout_view(request)}) and HttpResponseRedirect('/login/')
  </code></pre>
  
  <p>LoginView.py</p>
  
  <pre><code>from django.contrib import auth
  from django.http import HttpResponseRedirect
  
  def login_view(request):
      username = request.POST.get('username', '')
      password = request.POST.get('password', '')
      user = auth.authenticate(username=username, password=password)
      if user is not None and user.is_active:
          # Correct password, and the user is marked "active"
          auth.login(request, user)
          # Redirect to dashboard
          return HttpResponseRedirect('/')
      else:
      # Show a message     
          return 'Please enter your username and password below.'
  </code></pre>
  
  <p>login.html - simple form</p>
  
  <pre><code>&lt;center&gt;
  
  &lt;p&gt;{{ login }}&lt;/p&gt;
  
    {% if form.errors %}
      &lt;p class="error"&gt;Sorry, that's not a valid username or password&lt;/p&gt;
    {% endif %}
  
  
    &lt;form action="./" method="post"&gt;
          &lt;table border="0"&gt;
      &lt;tr&gt;
      &lt;td&gt;
      &lt;label for="username"&gt;Username:&lt;/label&gt;
      &lt;/td&gt;
      &lt;td&gt;
      &lt;input type="text" name="username" value="" id="username"&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
      &lt;td&gt;
      &lt;label for="password"&gt;Password:&lt;/label&gt;
      &lt;/td&gt;
      &lt;td&gt;
      &lt;input type="password" name="password" value="" id="password"&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
      &lt;input type="submit" value="login" /&gt;
      &lt;input type="hidden" name="next" value="/" /&gt;
      {% csrf_token %}
    &lt;/form&gt;
  
  &lt;/center&gt;
  </code></pre>
  
  <p>I followed the Django book tutorial on this and according to it, it all should work just fine. As you can see I've also tried using the 'next' hidden field in my form which doesn’t work either. Any help would be appreciated. I wonder what I'm missing here. Thanks!</p>