title: Django - Ajax modal login/registration
body: <p>I have a project in which I need to pop a modal window for not authenticated users.</p>
  
  <p>This modal will allow to login directly <strong>or</strong> create an account.</p>
  
  <p>So it will contain two forms:</p>
  
  <ul>
  <li><code>django.contrib.auth.forms.AuthenticationForm</code></li>
  <li><code>registration.forms.RegistrationForm</code></li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/IayFR.png" alt="Modal tabbed forms"></p>
  
  <p>Here is my view to get both forms:</p>
  
  <pre><code>def ajax_registration(request):
      obj = {
          'login_form': AuthenticationForm(),
          'registration_form': RegistrationForm(),
      }
      return render(request, 'common/ajax_registration.html', obj)
  </code></pre>
  
  <p>And my template displaying the forms tabbed</p>
  
  <pre><code>&lt;ul class="nav nav-tabs"&gt;
    &lt;li&gt;&lt;a href="#tab1" data-toggle="tab"&gt;{% trans 'Login' %}&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="#tab2" data-toggle="tab"&gt;{% trans 'Registration' %}&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;div class="tab-content"&gt;
    &lt;div class="tab-pane active" id="tab1"&gt;
      {{ login_form|bootstrap }}
    &lt;/div&gt;
    &lt;div class="tab-pane" id="tab2"&gt;
      {{ registration_form|bootstrap }}
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Question is: Since I'm using ajax to display this modal, How can I validate the selected form, preferably using the already written <a href="http://docs.b-list.org/django-registration/0.8/views.html#registration.views.register" rel="noreferrer"><code>django-registrations register</code></a> &amp; <a href="https://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.views.login" rel="noreferrer"><code>django.contrib.auth login</code></a> views ?</p>