saran3h
saran3h

Reputation: 14022

Convert file located in relative path into a Django File object

I have a file located at below relative path in my source code:

docs/Shootsta_Videographer_critical_info.pdf

I want to convert this file into a Django File object. Please help.

Upvotes: 0

Views: 419

Answers (1)

Krukas
Krukas

Reputation: 677

The docs for Django https://docs.djangoproject.com/en/2.2/ref/files/file/ states that the File constructor accept a Python file object.

So something like this:

from django.core.files import File
django_file = File(open('<base_dir>/docs/Shootsta_Videographer_critical_info.pdf'))

Upvotes: 1

Related Questions