getting image to show in view in django

21 views
Skip to first unread message

John McClain

unread,
Oct 13, 2019, 8:03:57 AM10/13/19
to Django users
Hello,

I have built mvc django store and am able to see my images related to the products I upload. However, I am not able to see images like banners or such that are placed in html pages.

I am not using virtual environment

I am using vs code ide

my site is served through free heroku version

product images are hosted on s3 bucket

I originally built the project in cloud9 then moved to gitpod and then now am in vs code. Each time I have had to adjust the configuration to work in the new environments. In this latest version I am now wanting to include images unrelated to the products which are uploaded through the admin panel

can anyone me figure out why they are not showing

setting.py

AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
# AWS_S3_CUSTOM_DOMAIN = '%s.s3-eu-west-1.amazonaws.com' % AWS_STORAGE_BUCKET_NAME


#STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'custom_storages.StaticStorage'

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# STATICFILES_DIRS = (
#     os.path.join(BASE_DIR, "static"),
# )

MEDIAFILES_LOCATION = 'media'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION)


accounts/views.py
def how_to(request):
    """A view that displays the how_to page"""
    return render(request, "how_to.html")


how_to.html        html page lrft out other content just focusing on drawing images to page at the monet
{% extends 'base.html' %}
{% load staticfiles %}
{% block content %}
<img src="{% static '/images/Hi-I-am-Alpha.png'%}" alt="">
<img src="{% static '/images/and-I-am-Beta.png'%}" alt="">
<img src="{% static '/images/and-I-am-Charlie.png'%}" alt="">


Rajkumar Mittal

unread,
Oct 13, 2019, 8:20:04 AM10/13/19
to Django users
Your base.html page works correctly? Because you are using it in how_to.html page
Reply all
Reply to author
Forward
0 new messages