如何修复“从其他页面加载内容时jquery中的500错误”?

时间:2019-09-06 13:07:43

标签: jquery django-templates

因此,我正在使用javascript在列表页面中加载详细信息,它可以正常工作,但问题再次出来。因此,我执行了相同的操作,但是通过关闭div触发了点击。但它返回500错误。

 <script type="text/javascript" language="javascript">
    $(document).on('click','figure', function(){
      var pk = $(this).data('id');
      $('#main').load("/gallery/"+ pk +" #content", function() {
        $('.close').click(function(){
          $('#content').load("/gallery/"+" #main", function() {
            /// can add another function here
          });
        });

      });
    });

</script>

本地物体看起来像

{% block body %}
<div id="main">
<section class="gallerySection">
<div class="gallery">
  {% for obj in object_list %}
  <figure data-id="{{obj.pk}}">
    <img src="{{obj.photo.url}}" />

    <figcaption>
      <div class="additional">
        <p id="caption">{{obj.caption}}</p>
      </div>
      <p id="credit">{{obj.credit}}</p>
    </figcaption>


  </figure>
  {% endfor %}


</div>
</section>
</div>

{% endblock body %}

现在在/ gallery / pk中,我正在#内容就像

{% block body %}
<div id="content">
<div class="close" data-id="{{object.id}}">
  <img id="close" src="{% static '/images/close.png' %}" />
  </div>
<section class="detailSection">

  <div class="imagewrap">
    <img src="{{object.photo.url}}" />
  </div>
  <div class="content">
      <h1>{{object.caption}}</h1>
    <p>{{object.description}}</p>
    <span>{{object.credit}}</span>
  </div>

  <p id="credit">{{obj.credit}}</p>
  </section>
</div>
{% endblock body %}

错误: The server error

这表示模板名称为gallery_list.page.html,但实际上并不存在。

Views.py

class GalleryView(AjaxListView):
    context_object_name = "object_list"
    template_name = "gallery.html"

    def get_queryset(self):
        return Gallery.objects.all()


class GalleryDetailView(DetailView):
    model = Gallery
    template_name = "gallery_details.html"

Where my browser says is the error

0 个答案:

没有答案