Answer the question
In order to leave comments, you need to log in
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 %}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question