Ephes Blog

Miscellaneous things. Not sure what to put here, yet.


Using staticfiles with STORAGES in Django 4.2

The other day I was trying to improve a management command of django-cast to make it easier to backup media files like images and videos. There's already an existing command, but it had to assume that you stored your media files on s3 and wanted the backup to be stored on the local filesystem. It would be great if you could configure your production and backup storage and have the backup command work either way. And the new STORAGES setting added in Django 4.2 looks like a perfect fit for this. So I tried using such a configuration:

STORAGES = {
    "default": {"BACKEND": "config.settings.local.CustomS3Boto3Storage"},
    "staticfiles": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
        "OPTIONS": {
            "location": "staticfiles",
            "base_url": "/static/",
        },
    },
    "production": {"BACKEND": "config.settings.local.CustomS3Boto3Storage"},
    "backup": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
        "OPTIONS": {
            "location": ROOT_DIR.path("backups").path("media"),
        },
    },
}

But it didn't work. It took me longer than I would like to admit to figure out that I should have used this config:

STORAGES = {
    "default": {"BACKEND": "config.settings.local.CustomS3Boto3Storage"},
    "staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"},
    "production": {"BACKEND": "config.settings.local.CustomS3Boto3Storage"},
    "backup": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
        "OPTIONS": {
            "location": ROOT_DIR.path("backups").path("media"),
        },
    },
}

If you want to replace django.contrib.staticfiles.storage.StaticFilesStorage with whitenoise for production, it's sufficient overwrite the backend in the production settings like this:

STORAGES["staticfiles"]["BACKEND"] = "whitenoise.storage.CompressedManifestStaticFilesStorage"

Weeknotes 2023-08-07

Mit so radikalen Aktionen wird das Klima absolut nichts erreichen. --Christoph Dolna-Gruber

The new Wagtail 5.1 release broke the video and audio choosers in django-cast so there's a new release 0.2.17 that fixes that. While I was at it, I also added some more documentation for the video and audio features. Lots of distractions this week with school and kindergarten stuff, but hopefully things will pick up soon 😅.

Last week I picked up a musical instrument for the first time in over two years. I hadn't been able to play before because I just didn't have the time. Now I'm thinking about getting back into the habit.

Articles

Software

Weeknotes

Videos

Podcasts


Weeknotes 2023-07-31

Don’t worry about people stealing your ideas. If your ideas are any good, you’ll have to ram them down people’s throats. --Howard Aiken

Last week of vacation. Back to work...

Articles

Weeknotes

Software

Podcasts

Out of Context Images


Weeknotes 2023-07-24

People who prefer ketchup over mustard are annoying because as soon as you say you like mustard, they go on and on about how much they hate it. Like, okay. You have the same flavor palette you had when you were 5 but that doesn’t mean you should insult what I put in my coffee. --Roxi Horror

Even more vacation.

Articles

Weeknotes

Software

Podcasts

Out of Context Images


Weeknotes 2023-07-17

There must be in-groups whom the law protects but does not bind, alongside out-groups whom the law binds but does not protect. --Frank Wilhoit - the composer, not the political scientist..


On vacation. Didn't do anything computer related.

Articles

Software

Podcasts

Out of Context Images