#Problem with static and media directory

14 messages · Page 1 of 1 (latest)

carmine lichen
#

You said it's static then you show code that handles uploads, so which is it?

broken bobcat
#

Ok you're right. So even when an admin adds an item through the admin panel, it is not a static image, but should be placed in media/images/... Even though it's not a user-uploaded photo?

thorn gorge
#

There is no problem with the code as it looks to be working as I would expect an ImageField to work.

I would guess that your understanding of static files and media files is incorrect.

Does an admin user upload these images?

#

User uploaded doesn't distinguish between the user types you might have

#

Static files live in your codebase, media files get uploaded at runtime.

carmine lichen
#

Though I always say that "Media == user uploads" is not really correct

#

Also how do you serve media files? If you are in debug using runserver it needs manually added url to serve media

broken bobcat
#

Ok, so I just didn't understand:
static: static things that are needed to render the page (css, js, images)
media: which links are created/added to be displayed dynamically?

broken bobcat
#

Ok, so even if the admin adds any photo to the database, it is a media file and not a static one?

#

so the upload should looks like this:

def upload_to_path(instance, filename):
    category_slug = slugify(instance.category.name)
    return f'images/{category_slug}/{filename}'
#

i remove static/ in the return

carmine lichen
#

static files ~= files created during development process and kept under version control
media files ~= files created during operation of site and might change without developer commits