Django s3 bucket upload with out admin static css and js

Is it possible to upload the files into s3 buckets in Django without uploading default django admin css, js files?

all files are getting uploaded; but i need only uploaded files in S3 buckets. Is there any work around for this? Any changes to settings file that will help to achieve this ?

You are mixing static files with media files

static files are your css, js, icons etc including your django admin css, js etc

media files are user uploaded or other media files your application needs to store somewhere and use later.

If you follow this article and ignore the static files section you can achieve what you want.

# settings.py

# Import necessary modules
import os
from storages.backends.s3boto3 import S3Boto3Storage


# Set the required AWS credentials
AWS_ACCESS_KEY_ID = 'your-access-key-id'
AWS_SECRET_ACCESS_KEY = 'your-secret-access-key'
AWS_STORAGE_BUCKET_NAME = 'your-bucket-name'
AWS_S3_REGION_NAME = 'your-region-name'  # e.g. us-west-2

# Optional: Set custom domain for static and media files
# AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'

# Set the media files locations
MEDIAFILES_LOCATION = 'media'

class MediaStorage(S3Boto3Storage):
    location = MEDIAFILES_LOCATION
    file_overwrite = False

# Configure static and media files storage
DEFAULT_FILE_STORAGE = 'your_app_name.settings.MediaStorage'

# Set media URLs
MEDIA_URL = f'https://{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com/{MEDIAFILES_LOCATION}/'

You also need to install django-storages first

pip install django-storages

This also works directly with FileField in your django models

Back to Top