为什么我的pdf没有在django模板中显示?

时间:2018-06-11 12:43:56

标签: django django-models django-templates django-views

我正在尝试在html模板中显示pdf文件,并且还能够更新该pdf文件,我阅读了有关如何显示pdf文件的教程,但我不确定为什么我的不知道'真的有用,我有一个名为Reference

的模型
class References(models.Model):

    REFERENCE_MATERIAL = (
        ('seating', 'Seating Plan'),
        ('organization', 'Organization Chart')
    )

    # the variable associated with the reference
    reference_name = models.CharField(max_length=100, choices=REFERENCE_MATERIAL,)

    reference_file = models.FileField(null=True, blank=True, upload_to='references/')

    date_updated = models.DateField(auto_now=True)


    # on submit click of update entry page, it redirects to the url below.
    def get_absolute_url(self):
        return reverse('references-home')

以下是更新参考的视图和显示参考的视图

class SeatingReferenceView(generic.ListView):
    context_object_name = 'seating_plan'
    template_name = 'catalog/references-seating.html'

    def get_queryset(self):
        return References.objects.filter(reference_name='seating').order_by('date_updated').first()

def reference_update(request):
    if request.method == 'POST':
        form = UploadReference(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('references-home')
    else:
        form = UploadReference()
    return render(request, 'catalog/references_update.html', {'form': form,})

这是我的模板

<div class="container maintenance-container">


  <div class="row" >
    <div class="maintenance-title">
      <h1 class="mainrow">Seating Plan</h1>
      <h4 class="maintenance-under">Seating Plan for Kitchener Floor 1</h4>
    </div>
  </div>

  <div class="row">
      {% if seating_plan %}
      <div class="col-lg-12">
        {{ seating_plan.read }}
      </div>



      {% else %}
        <div class="col-lg-12">
          <div class="mainpanelcontent">
             <h4>There are no seating plans to display</h4>
          </div>

        </div>

      {% endif %}

  </div>
</div>
{% endblock %}

但是我在html模板中没有收到任何内容,我将文件存储在/media/references下的文件夹中,我可以看到文件当前在那里,我可以在我的数据库中看到reference_file列,其中包含名为seatingplan.pdf的文件,但仍未显示任何内容。谢谢!

0 个答案:

没有答案