title: How to put login and registration form on same index page
body: <p>As of now, I have my registration form and my log in form on two different pages, I can't seem to put them in one view because the way I did it, the views require different return statements. So here is my registration view function:</p>
  
  <pre><code>def register_user(request):
      if request.method == 'POST':
          form = MyRegistrationForm(request.POST)
          if form.is_valid():
              form.save()
              return HttpResponseRedirect('/accounts/register_success')
  
      args = {}
      args.update(csrf(request))
  
      args['form'] = MyRegistrationForm()
  
      return render_to_response('register.html', args)
  
  def register_success(request):
           return render_to_response('register_success.html')
  </code></pre>
  
  <p>and here is my log in and authentication view:</p>
  
  <pre><code>def login(request):
      c = {}
      c.update(csrf(request))
      return render_to_response('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>Here is the template for the log in page:</p>
  
  <pre><code>            &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;/form&gt;
  </code></pre>
  
  <p>and here is the template for the registration page:</p>
  
  <pre><code>&lt;h2&gt;Register&lt;/h2&gt;
  &lt;form action="/accounts/register/" method="post"&gt;{% csrf_token %}
  {{form}}
  
  &lt;input type="submit" value="Register" /&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>Again, I can't seem to put them together because the views have to return different things.. any idea on how to do it?</p>
  
  <p>EDIT: This is my urls.py:</p>
  
  <pre><code>url(r'^admin/', include(admin.site.urls)),
  url(r'^$', index),
  url(r'^accounts/auth/$', auth_view),
  url(r'^invalid/$', invalid_login),
  url(r'^accounts/register/$', register_user),
  url(r'^accounts/register_success/$', register_success),
  </code></pre>
  
  <p>so it will only use the register_user view if the url is accounts/register, I want it to user the register_view view if it is the homepage (^$). My index view is this:</p>
  
  <pre><code>def index(request):
      c = {}
      c.update(csrf(request))
      return render_to_response('index.html', c)
  </code></pre>
  
  <p>it basically just adds a csrf token to my index.html (log in template, as seen above). This is why I want to be able to somehow merge index and the register_user view, since register_user view calls the actual form = MyRegistrationForm(request.POST) which is used in the registration template (the registration template uses {{form}}</p>