How can I acces to my AWS S3 bucket in django?

I am working for the first time with aws s3, where I have images to upload from the django admin, everything works perfect on localhost, but once deployed the images are uploaded but not displayed on the web My setting.py



AWS_ACCESS_KEY_ID = 'my acceskey'
AWS_SECRET_ACCESS_KEY = 'my secret key'
AWS_STORAGE_BUCKET_NAME = 'mybucketname'
AWS_DEFAULT_ACL = None
AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
 
STATIC_LOCATION = 'static'
PUBLIC_MEDIA_LOCATION = 'media'
MEDIA_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{PUBLIC_MEDIA_LOCATION}/'
DEFAULT_FILE_STORAGE = 'portfolio.storages.MediaStore'


My models

class Project(models.Model):
    name = models.CharField(max_length=100)
    description = models.CharField(max_length=200)
    link = models.CharField(max_length=250)
    another_link= models.CharField(max_length=250, null= True, blank=True)
    image = models.ImageField(upload_to='media/')

My views

def project(request):
    projects = Project.objects.all().order_by('-id').values()

    return render(request, "works.html", {"projects": projects})

My template

{% for project in projects %}
        {% csrf_token %}
        <div class="row">
          <div class="col-md-12 col-md-offset-1">
            <div class="row">
              <div class="col-xs-12 col-md-6">
                <h3>{{project.name}}</h3>
                <p style=> {{project.description}} </p>
                <a  href="{{project.link}}" target="_blank" class="btn btn-default">Source Code</a>
                <a  href="{{project.another_link}}" target="_blank" class="btn btn-default">See Live</a>
              </div>
              <div class="col-xs-6 col-md-4">
                <img src="{{project.image.url}}"  width="360" height="200" >
              </div>
            </div>
          </div>
        </div>
        {% endfor %}

In the Html not return a asw link, return this

<img src="" width="360" height="200">

Images are loaded perfectly in the S3 bucket but are not displayed in the HTML.

Back to Top