Problems loading static files in Django in deploy in heroku

0

I'm trying to deploy an app that I started in django in heroku, but I'm having trouble loading the css / js / imgs files, here's how my folders and settings look!

settings.py

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static/'),
)

Iloadthecsslikethis:

<linkrel="stylesheet" href="{% static 'bootstrap/css/bootstrap.css' %}"/>
<link rel="stylesheet" href="{% static 'template/style.css' %}" />
<link rel="stylesheet" href="{% static 'fontawesome/css/fontawesome-all.min.css' %}" />

My problem is that I can deploy but I can not load the static files on the page!

    
asked by anonymous 11.12.2017 / 15:27

1 answer

1

Maybe what you're missing is that you set yourself in Django mode to serve the static files. At documentation you enter the code below as a hack in urls.py of your project to be able to do this:

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

There is a way to already set up for Heroku using WhiteNoise . I'll leave some links below as a reference for this.

13.12.2017 / 03:43