0

I have images downloaded in the following path but they refuse to load for me. Any idea what I may have configured incorrectly that is forcing this?

C:\Users\xxx\Python\Price Tracking\Django\mysite\polls\static\polls\images

  • stl.jpg
  • chicago.jpg
  • nyc.jpg

enter image description here

settings:

INSTALLED_APPS = [
    'polls.apps.PollsConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_plotly_dash.apps.DjangoPlotlyDashConfig',
]

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

STATIC_URL = '/static/'

html:

{% load static %}

    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div class="carousel-inner">
            <div class="carousel-item active">
                <img class="d-block w-100" src="{% static 'polls/chicago.jpg' %}" alt="First slide">
            </div>
            <div class="carousel-item">
                <img class="d-block w-100" src="{% static 'polls/nyc.jpg' %}" alt="Second slide">
            </div>
            <div class="carousel-item">
                <img class="d-block w-100" src="{% static 'polls/stl.jpg' %}" alt="Third slide">
            </div>
        </div>
        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
        </a>
    </div>
1
  • Your html should read <img class="d-block w-100" src="{% static 'polls/images/chicago.jpg' %}" alt="First slide"> Commented Dec 29, 2020 at 22:27

1 Answer 1

1

First you write that images are in ... polls/static/polls/images/ but in the template tag you have /polls/xyz.jpg

For the rest you need to tell if you are in development with runserver and Debug=True (then files are taken from the app/static folders as you place them) or in deployment on e.g. a Apache server (then you need to serve them from Apache directly ... see serving static files on django docs

Sign up to request clarification or add additional context in comments.

6 Comments

Shouldn't the Settings.py file tell it to look for */static/ and then start there, which would cut off the rest of the path and leave me with path/nyc.jpg (aka what I have)? Also, this is currently on my offline server 127.0.0.1:7000.
Runserver will look in your apps/static/+path from your template tag {% static 'path/file' %}
127.0.0.1:7000 is served by runserver or another?
I also just tried updating polls/nyc.jpg to polls/static/nyc.jpg with no luck
Weirdly enough, some images work while some do not even within the same folder... Are there any other requirements that I'm not thinking of?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.