tom
tom

Reputation: 2365

Where in Django project to store a single image file that is never served to the user

Suppose I have a Django project that contains a view which generates a PDF, and requires a logo on the top of the PDF. This logo is stored as an image file, and is not ever referenced in a template. Static files are stored in an S3 bucket.

It feels like this logo should not be a static file, since it does not need to be stored in S3. A user should never grab this file directly; the view which generates this PDF is the only thing that will ever open the file. The file does not need a URL to see it online. It also feels like this isn't a media file, since it is not something uploaded by a user. Lastly, I don't think that this is something that needs to be stored in the database, as this image does not have a "model" of which other objects would ever need to be created.

Where in the project structure should this type of file be stored? Is there a standard location for this type of file?

Upvotes: 1

Views: 67

Answers (1)

allcaps
allcaps

Reputation: 11228

You can use multiple storage classes. Suppose your DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'. Than you can still create an exeption to the default like this:

from django.db import models
from django.core.files.storage import FileSystemStorage

fs = FileSystemStorage(location='/media/photos')

class Car(models.Model):
    ...
    photo = models.ImageField(storage=fs)

The files stored to system don't have to be served but can exist to be processed when needed.

https://docs.djangoproject.com/en/1.8/topics/files/

Upvotes: 4

Related Questions