Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
Django custom static files not collected to s3 bucket

I'm configuring my Django project to use S3 buckets to store static and media files, both for local and production settings.

My project tree is as follows:

   src/
      blog/
          settings/
                  __init__
                  local.py
                  production.py
          s3utils.py
          [..]
      [..]

My local.py:

access_key = "xx"
secret_key = "yy"

AWS_ACCESS_KEY_ID = access_key
AWS_SECRET_ACCESS_KEY = secret_key
AWS_STORAGE_BUCKET_NAME = 'zz'


STATICFILES_STORAGE = 'blog.s3utils.StaticRootS3BotoStorage'
DEFAULT_FILE_STORAGE = 'blog.s3utils.MediaRootS3BotoStorage'
S3DIRECT_REGION = 'us-west-2'
S3_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
MEDIA_URL = 'http://%s.s3.amazonaws.com/media/' % AWS_STORAGE_BUCKET_NAME
MEDIA_ROOT = MEDIA_URL
STATIC_URL = S3_URL + "/static/"
ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

import datetime

two_months = datetime.timedelta(days=61)
date_two_months_later = datetime.date.today() + two_months
expires = date_two_months_later.strftime("%A, %d %B %Y 20:00:00 GMT")

AWS_HEADERS = { 
    'Expires': expires,
    'Cache-Control': 'max-age=%d' % (int(two_months.total_seconds()), ),
}

my s3utils.py:

from storages.backends.s3boto import S3BotoStorage

StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static') 
MediaRootS3BotoStorage  = lambda: S3BotoStorage(location='media') 

When I run:

python manage.py collectstatic

only (django) admin static files are copied to my s3 bucket.

I thought that the problem was that I misconfigured the permission of my IAM user, but actually I do have the permissions to copy the 'admin/' files to the s3 bucket.

Thank you for any help you can provide.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Add STATICFILES_DIRS to your settings.

STATICFILES_DIRS = [
    "/path/to/your/static",
]

https://docs.djangoproject.com/en/1.10/ref/settings/#std:setting-STATICFILES_DIRS

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!