Problems loading Static files to Django in deploy on Heroku

Asked

Viewed 1,187 times

0

I’m trying to deploy an app I started in Jango on Heroku, but I’m having trouble loading the css/js/imgs files, follow below as my folders and settings related to it!

py Settings.

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/'),
)

Pasta do Projeto

I load css like this:

<link rel="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’t load the Static files on the page!

  • has already run the command Heroku run python Manage.py collectstatic

1 answer

1


Maybe what is missing is you set so that in development mode Django serves the static files. In documentation you enter the code below as a hack in the 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 so that Heroku using the WhiteNoise. I’ll leave some links below as a reference for this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.