Ian Carpenter
Ian Carpenter

Reputation: 8626

Is an uploaded image, a static file in Django?

I am developing an app in Django 1.6 and would like to know if the photos that I upload via the admin interface are "static files" in Django terminology.

I have this model:

from django.db import models

class ShowroomDetail(models.Model):
    title = models.CharField(max_length=1000)
    description = models.CharField(max_length=4000)     

class ShowroomPhoto(models.Model):
    showroom = models.ForeignKey(ShowroomDetail, related_name='photos')
    photo = models.ImageField(upload_to='images/')

which I using as a basis of developing a page where there can be one or more images displayed along with the title and description. The images will only ever be uploaded by the admin interface and more photos for the page may be added at a later date.

So are these uploaded photo's "static files"?

Upvotes: 2

Views: 672

Answers (2)

Maxime Lorant
Maxime Lorant

Reputation: 36161

No. An image uploaded through the website will be stored in the MEDIA_ROOT folder. It is considered then as a media file and not a static file. For your example, if MEDIA_ROOT = '/path/to/project/media/, then your photos will be stored in media/images/.

The difference is staticfiles will be collected for each application and are part of the code. Typically it is image for the design, CSS files, Javascript, etc. They are necessary to run the project.
Media files are files uploaded through the administration or by user through a special application to add content (avatar, gallery image, message attachment...). This content is independent of the code of the project and is considered as content.

Related: What is the difference between static files and media files in Django?

Upvotes: 5

Marcin
Marcin

Reputation: 49846

"static files" as a term of art refers to the static files, and the location you configure for it. Uploaded files could be found by static files if you upload them to a location which static files uses. Obviously, security issues abound.

Upvotes: -1

Related Questions