I’m running a django application in a docker container but the static files are not loading. I run the app through the django server itself, with DEBUG activated, the static files folder are in the root of the project, and “django.contrib.staticfiles” is present in my settings, even so, the css and javascript are not found .
Detail, this application works perfectly on my local machine, but when I run it through the Docker container, the static files do not work. Below are details of my project:
FROM python:3.8
WORKDIR /code
COPY requirements.txt /code
RUN pip install --no-cache-dir -r requirements.txt
COPY ./app /code
I assigned permission 755 in the static files directory, I changed the ports in docker compose, updated the python/django version and nothing solved it…
First things first, running the development server in production is a security and scaling nightmare. Don’t do that (Here the deployment docs for reference). If you’re just testing or developing, then sure thats fine.
If i had to guess, you’re probably not running the container instance with DEBUG=True.
Feel free to share your settings.py (please make sure you remove any identifiable information such as the SECRET_KEY beforehand).
Your urls.py could also be the culprit. But there is no telling without the actual code or more specific error messages.
Hello, for now I’m just testing the application in docker, but this problem is preventing me from moving forward. DEBUG is enabled. As for urls.py, here is its contents.
from django.contrib import admin
from django.contrib.auth import views
from django.urls import path, include
from seca.views import my_logout, home
urlpatterns = [
path('login/', views.LoginView.as_view(), name='login'),
path('logout/', my_logout, name='logout'),
path('', home, name='home'),
path('pessoas/', include('pessoas.urls')),
path('apiarios/', include('apiarios.urls')),
path('revisoes/', include('revisoes.urls')),
path('graficos/', include('graficos.urls')),
path('admin/', admin.site.urls)
]