BS 3 では、モーダル ダイアログを呼び出すときに、外部ページをモーダルにロードする場合、モーダルのデータを非表示にするときに、次の js を挿入してモーダルのデータを削除する必要があることを認識しています。
$('body').on('hidden.bs.modal', '#ModalID', function () {
$(this).removeData('bs.modal');
});
これを使用してモーダルをロードします:
$('.select-modal').click(function(ev) {
var url = $(this).attr('href');
$('#ModalID').modal({
show: true,
remote: url
});
return false;
画像を含むコンテキストで TemplateView をロードします。
class ImageSelectView(LoginRequiredMixin, TemplateView):
template_name = 'imageviewer/image_modal.html'
def get_context_data(self, **kwargs):
context = super(ImageSelectView, self).get_context_data(**kwargs)
context['images'] = Image.objects.for_user(self.request.user).order_by('-created')
return context
私の開発マシンでは問題なく動作し、Image に追加された新しいアイテムが表示されます。本番サーバーでは、変更はモーダル内に反映されません。Memcache のクリア、ブラウザーのキャッシュのクリア、URL のロードなどのさまざまな方法を試しました。