Someone has asked the exact same question in April, without any answer. But since he provided too little information; the question was abandoned.
I have the same problem. Within a main_page.html
I have this line:
<a href="/contact/edit/{{ item.id }}" title="Edit">edit</a>
Once you click there, the edit template shall appear inside a twitter bootstrap modal.
url.py
(r'^contact/edit/(?P<contact_id>\d+)/$', contact_view),
view.py
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)
This is usually how the contact.html would look like:
<form class="well" method="post" action=".">
{% csrf_token %}
{{form.as_p}}
<input class="btn btn-primary" type="submit" value="Save" />
<input name="cancel" class="btn" type="submit" value="Cancel"/>
</form>
I could put that inside a <div class="modal-body">
.
But then how do I open the modal from view?