0

I have been trying to figure out why the static files are loading for quite a few hours by now , but still can't figure our whats wrong. Could you please let me know what you thing could be the cause ? The following are:

My project structure:

├── example_project
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
|   └── pages
|      ├── __init__.py
│      ├── admin.py
│      ├── apps.py
│      ├── models.py
│      ├── tests.py
│      └── views.py
├── templates
    ├── home.html
│
│──static
   ├── css
     ├── bootsrtap.min.css
   ├── js
   ├── images
└── manage.py

These are my settings.py(I haven't put STATIC_ROOT because I dont need to collectstatic):

STATIC_URL = '/static/'

STATICFILES_DIR=[
    os.path.join(BASE_DIR,'static'),
]

This is bootstrap.min.css:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

This is the template where I am trying to load bootstap ( and other static files) in:

{% load static %}
{% for product in object_list %}

<link rel="stylesheet" href="{% static 'css/bootstrap.min'%}">

<div class="card" style="width: 18rem;">
    <img class="card-img-top" src="{% static 'products/images/pavoreal-beach-resort.jpg'%}" alt="Card image cap">
    <div class="card-body">
      <h5 class="card-title">{{product.name}}</h5>
      <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
      <a href="#" class="btn btn-primary">Go somewhere</a>
    </div>
  </div>

{% endfor %}

I have also tried to change the static into the app but still... no success..Thanks you !

Peter Malik
  • 403
  • 4
  • 14
  • Does this answer your question? [django html template can't find static css and js files](https://stackoverflow.com/questions/66437690/django-html-template-cant-find-static-css-and-js-files) – Ivan Starostin Apr 29 '21 at 12:41
  • Thanks for your answer Ivan ! I have followed your advice in your answer and have put in settings.py STATIC_ROOT = os.path.join(BASE_DIR, 'static') and have then ran manage.py collectstatic , but then also seems like it doesnt render the style or the image from static/image/... – Peter Malik Apr 29 '21 at 13:18

0 Answers0