title: How do I insert a django form in twitter-bootstrap modal window?
body: <p>Someone has asked the exact <a href="https://stackoverflow.com/questions/9979622/how-do-i-insert-a-django-form-in-twitter-bootstrap-modal-window">same question</a> in April, without any answer. But since he provided too little information; the question was abandoned.</p>
  
  <p>I have the same problem.  Within a <code>main_page.html</code> I have this line:</p>
  
  <pre><code>&lt;a href="/contact/edit/{{ item.id }}" title="Edit"&gt;edit&lt;/a&gt;
  </code></pre>
  
  <p>Once you click there, the edit template shall appear inside a twitter bootstrap modal.</p>
  
  <p><strong>url.py</strong></p>
  
  <pre><code>(r'^contact/edit/(?P&lt;contact_id&gt;\d+)/$', contact_view),
  </code></pre>
  
  <p><strong>view.py</strong></p>
  
  <pre><code>def contact_view(request, contact_id=None):
      profile = request.user.get_profile()
      if contact_id is None:
          contact = Contact(company=profile.company)
          template_title = _(u'Add Contact')
      else:
          contact = get_object_or_404(profile.company.contact_set.all(), pk=contact_id)
          template_title = _(u'Edit Contact')
      if request.POST:
          if request.POST.get('cancel', None):
              return HttpResponseRedirect('/')
          form = ContactsForm(profile.company, request.POST, instance=contact)
          if form.is_valid():
              contact = form.save()
              return HttpResponseRedirect('/')
      else:
          form = ContactsForm(instance=contact, company=profile.company)
      variables = RequestContext(request, {'form':form, 'template_title': template_title})
      return render_to_response("contact.html", variables)
  </code></pre>
  
  <p>This is usually how the <strong>contact.html</strong> would look like:</p>
  
  <pre><code>        &lt;form class="well" method="post" action="."&gt;
              {% csrf_token %}
              {{form.as_p}}
              &lt;input class="btn btn-primary" type="submit" value="Save" /&gt;
              &lt;input name="cancel" class="btn" type="submit" value="Cancel"/&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>I could put that inside a <code>&lt;div class="modal-body"&gt;</code>. 
  But then how do I open the modal from view? </p>