title: Django Authentication (Custom Login Page)
body: <p>Im trying to write my own django login page. Eveything is ok up to the point where I try to login and I just get redirected back to the main login view.</p>
  
  <p><strong>TEMPLATE</strong></p>
  
  <pre><code>{% extends "bdayremind-maininput.html" %}
      {% block main %}
  
      &lt;form class="form-horizontal" name="LoginForm" action="/login/" method="post"&gt;
      {% csrf_token %}
      {% if next %}
          &lt;input type="hidden" name="next" value="{{ next }}" /&gt;
      {% endif %}
      &lt;div class="control-group"&gt;
      &lt;label class="control-label" for="username"&gt;Username&lt;/label&gt;
          &lt;div class="controls"&gt;
              &lt;input type="text" id="username" value="{{username}}" placeholder="Username"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="control-group"&gt;
          &lt;label class="control-label" for="password"&gt;Password&lt;/label&gt;
              &lt;div class="controls"&gt;
                  &lt;input type="password" name="password" id="password" placeholder="Password"&gt;
              &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="control-group"&gt;
          &lt;div class="controls"&gt;
              &lt;button type="submit" class="btn"&gt;Login&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;/form&gt;
      {% endblock %}
  </code></pre>
  
  <p><strong>URLS</strong></p>
  
  <pre><code>urlpatterns = patterns('',
      url(r'^bdayremind_maininput/$', 'birthdayreminder.views.main'),
      # login / logout
      (r'^login/$', 'birthdayreminder.views.login_user'),
      #(r'^logout/$', logout_page),
  )
  </code></pre>
  
  <p><strong>VIEWS</strong></p>
  
  <pre><code>import datetime
  from django.http import *
  from django.shortcuts import render_to_response
  from django.template import RequestContext
  from birthdayreminder.models import *
  from django.contrib.auth.decorators import login_required
  from django.contrib.auth import authenticate, login
  
  def login_user(request):
      username = password = ''
      if request.POST:
          username = request.POST.get('username')
          password = request.POST.get('password')
  
          user = authenticate(username=username, password=password)
          if user is not None:
              if user.is_active:
                  login(request, user)
                  return HttpResponseRedirect('birthdayreminder.views.main')
  
      return render_to_response('login.html',{'username': username}, context_instance=RequestContext(request))
  
  
  
  @login_required(login_url='/login/')
  def main(request):
  ........
  </code></pre>
  
  <p>Any Ideas ?</p>