R
R
Rem362018-05-14 20:53:35
Django
Rem36, 2018-05-14 20:53:35

How to open a file through a link?

Hello.

class File(models.Model):
  name = models.CharField(max_length=100)
  file = models.FileField()

def index(request):
  file = File.objects.all()
  context = {'file':file}
  return render(request, 'qwerty/index.html', context)

{% for i in file %}
<a href="{{i.file.url}}" target="blank">{{i.name}}</a>
{% endfor %}

Why is the file not opening? The same page only in the address of the file name? PDF file

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alex maslakoff, 2018-05-15
@teke_teke

I don’t know why it doesn’t open,
but there is one error - it should be target="_blank"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question