2

Many thanks for your support.I am a newbee to Django and Bootstrap.

When I downloaded a bootstrap template it came with a logo.png.If I point to this image with below code all works

<a href="#" class="navbar-brand">
    <!-- Logo Image -->
    <img src="{% static '/img/logo.png' %}" width="100" alt="" class="d-inline-block align-middle mr-2">
    <!-- Logo Text -->
    <span class="text-uppercase font-weight-bold">Brand Name</span>
</a>

However if I place a custom image(test.png) within the same folder? of logo.png and point to that.The site does not show the logo.

  1. I tried resizing test.png to same as logo.png
  2. I tried using other images on my system
  3. Only the default logo and images that comes with templates works.

What am i missing please? Please help me.

Aerials
  • 4,231
  • 1
  • 16
  • 20
chilledout
  • 23
  • 1
  • 5
  • 1
    Is this in your local development environment or on production? Can you show your folder structure where we can see the location of /img/logo.png? – dirkgroten Jan 10 '20 at 15:31

1 Answers1

1

If you are using a production server then:

You need to use python manage.py collectstatic to get your new image into the directory where your static files are being served. That directory you specify in the STATIC_ROOT setting in your project's settings.py.

After executing collectstatic you should be able to spin up the server and the image in your link should be test.png.

This is all Django, and nothing to do with Bootstrap.

Edit: As dirkgroten points out several ways of dealing with static files are explained here. Note the difference between the development server and a production server.

Aerials
  • 4,231
  • 1
  • 16
  • 20
  • 1
    This assumes the OP is deploying to production and the problem is there, which isn't clear. On the local development environment, STATIC_ROOT and collectstatic are irrelevant. – dirkgroten Jan 10 '20 at 15:33
  • 1
    A better reading is [Managing static files](https://docs.djangoproject.com/en/3.0/howto/static-files/) – dirkgroten Jan 10 '20 at 15:34
  • Thanks so much.I had a separate static folder defined for development and somehow forgotten it.All images were put in the production Static folder and when I copied them to the development static folder everything started working. Many Thanks – chilledout Jan 11 '20 at 04:08