Загрузить загруженный файл django .docx
У меня есть веб-сайт, на котором я загружаю файл .docx, а затем пользователи могут скачать документ.
моя модель
class Files(model.Model):
name = models.CharField(max_length=200)
doc_File = models.FileField(upload_to='media')
Мой взгляд
def Uploaded(request):
file = Files.objects.filter('doc_File')
return render(request, 'uploaded_files.html', {'file':file})
урлы
path('file, views.Uploaded, name='file'),
моя html-страница
{% block content %}
<h4>Download Document Below</h4>
{% for f in file %}
<a href="{% url 'f.url' %}" Download>{{f.url}}</a>
{% endfor %}
{% endblock %}
Я не могу скачать файл .docx может ли кто-нибудь помочь плиз ....
Ваш возврат не правильный, попробуйте
data = open(doc.name, "rb").read() //doc.name is youre filefield from your model
return HttpResponse(data, content_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document")