hello guys i try to display pdf file in my html page.
i have this models:
class HomeWork(models.Model):
nameFile = models.CharField('Name File',max_length=30)
file = models.FileField('File',upload_to="files",null=True)
course = models.ForeignKey(Course, on_delete=models.CASCADE)
user = models.ForeignKey(User,on_delete=models.CASCADE, null=True)
and this is the class view
class HomeWorksView(View):
def get(self,request,course_id,user_id):
course = Course.objects.get(id=course_id)
homeworks = HomeWork.objects.all()
print(homeworks)
return render(request,"HomeWorks.html",{'course':course, 'homeworks':homeworks})
i pass all the files i have in my db. and i want to display in my html file
this is my html file:
{% block content %}
<h1>{{course.name_course}}</h1>
{% if user.is_authenticated %}
<a href="{% url 'Category:u-f' course.id user.id%}">Upload FILE</a>
{% endif %}
{% if homeworks %}
<div class="row">
{% for hw in homeworks %}
<div class="col-md-4">
<br>
<div class="card">
{{hw.file.url}}
<iframe src=" {{hw.file.url}}" width="800px" height="400px"></iframe>
<div class="card-body">
<h4 class="card-title text-center"> <a class="Course" href=""><b>{{hw.nameFile}}</b></a></h4>
<h5 class="card-title"></h5>
</div>
<div class="col text-center">
</div>
<br>
</div>
</div>
{% endfor %}
</div>
{% endif %}
{% endblock content %}
but this is line <iframe src=" {{hw.file.url}}" width="800px" height="400px"></iframe>
tell me that: localhost refused to connect.