title: homepage login form Django
body: <p>I want to create a homepage with a header that asks to login with username/password and a login button to login. Currently, how I have my page set up is that pressing login will send me to a login page. I want to simply enter in the information and press "login" to login on the homepage of my site. How can I design my <code>urls.py</code> and <code>views.py</code> to perform login on the homepage?</p>
  
  <p>I have a <code>base.html</code> that is the template for my main page. Within the template, I made a <code>login.html</code> partial view:</p>
  
  <pre><code>&lt;form action='/accounts/auth/' method='POST'&gt; {% csrf_token %}
      &lt;div &gt;
          &lt;label for='username'&gt; Username &lt;/label&gt;
          &lt;input type='text' name='Username' id='username'&gt;
          &lt;label for='password'&gt;Password &lt;/label&gt;
          &lt;input type='password' name='Password' id='password'&gt;
          &lt;input type='submit' value='login'&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I am a bit confused for the <code>action</code> attribute as I'm not sure where to send that form data if I wanted to authorize login on the same page.</p>
  
  <p>My views.py</p>
  
  <pre><code>def login(request):
      c = {}
      c.update(csrf(request))
      return render(request, 'login.html', c)
  
  
  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)
          return HttpResponseRedirect('/accounts/loggedin')
      else:
          return HttpResponseRedirect('/accounts/invalid')
  </code></pre>
  
  <p>I'm not sure where to <code>HttpResponseRedirect</code> as well if logging in is all done on the home page.</p>
  
  <p>Perhaps I can do a <code>render(request,SomePartialView.html)</code> instead of <code>HttpResponseRedirect</code>.</p>
  
  <p>Here is my urls.py:</p>
  
  <pre><code>url(r'^$', 'photoblog.views.login'),   #displays login.html
  url(r'^accounts/auth/$', 'photoblog.views.auth_view'),    #authorize login
  </code></pre>