1

I want to save a file in database instead of uploading it to a server media file and save URL in Database, I want directly save file in the Database.

Right now I am doing this:

model.py:

File = models.FileField(upload_to='CSR/', null=True , blank = True)

template.html:

<td> {{certificate.File.url}} </td>

1 Answer 1

2

Django supports BinaryField which lets you store binary data in the database.

The Django docs state:

Abusing BinaryField

Although you might think about storing files in the database, consider that it is bad design in 99% of the cases. This field is not a replacement for proper static files handling.

If you do not want to store files into the filesystem of your webserver, you can use the django-storages library which provides options for Amazon S3, DigitalOcean and more.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.