Cannot Deploy Static Content and CSS on Render

This is the first Django project that I have tried to deploy.

It isn’t quite finished yet, but I wanted to try deploying a demo version first because doing so is also something that I need to learn. I’m deploying it on Render, because I have deployed a few static-content apps via Render successfully.

It’s just a small restaurant app based on tutorials from Meta’s Introduction to Backend course that I finished a few months ago. The course required building different parts of a restaurant website and its API, although surprisingly the final project didn’t ask for a fully-functioning website. So to practice my skills, that’s what I’ve been working on over the last few weeks.

I see that this appears to be a common issue. I can’t get any of the static content, nor the css, to load when I deploy the project to Render.

I have spent over 6 hours watching tutorial videos, reading blog posts and looking at various answers for how to deploy static content.

I now understand that Django only looks after static content in development mode, so a package like whitenoise, or something similar, is required for production.

I’ve tried everything under the sun. I’ll include the Github repo here, and you’ll be able to see how many changes I’ve made while trying what Render says I should do on their official page; numerous different YouTube tutorials, and numerous responses to similar questions asked across forums. I’m so stuck that I feel I have no option but to ask, even though it appears to be a common question on forums.

The styling and images load only on the homepage if I make DEBUG = True, but are not present on any other page.

In my settings.py file, I have included:

.....
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'djoser',
    'restaurant',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    "whitenoise.middleware.WhiteNoiseMiddleware",
    'django.contrib.sessions.middleware.SessionMiddleware',
    # ‘django.contrib.staticfiles.middleware.StaticFilesMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
   
STATIC_URL = 'restaurant/static/'

STATIC_ROOT = BASE_DIR/'assets/'

STATICFILES_DIRS = [
    "restaurant/static/",
]

MEDIA_URL = '/media/'

STATICFILES_STORAGE = "whitenoise.storage.CompressedStaticFilesStorage"
.....

I’ve tried by adding whitenoise.runserver_nostatic to the INSTALLED_APPS; adding and taking away different things others have suggested. I added various lines to the root directory urls.py file, as suggested by others in forum posts.

‘django.contrib.staticfiles.middleware.StaticFilesMiddleware’ is hashed-out because someone recommended it on another forum post, although including it made the deploy fail, and other people said that it isn’t needed.

I’ve added a build.sh file:

#!/usr/bin/env bash
# exit on error
set -o errexit

pip install -r requirements.txt

python manage.py collectstatic --no-input
python manage.py migrate

the root directory urls.py file is currently:

from django.contrib import admin
from django.urls import path, include
from rest_framework import routers
from restaurant import views
from rest_framework.authtoken.views import obtain_auth_token
# from .settings import DEBUG
# from django.contrib.staticfiles.urls import staticfiles_urlpatterns

router = routers.DefaultRouter()
# router.register(r'users', views.UsersView)

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('restaurant.urls')),
    path('', include(router.urls)),
    path('', include('django.contrib.auth.urls')),
    path('auth/users/', views.signup, name='sign-up'),
    path('auth/', include('djoser.urls')),
    path('auth/', include('djoser.urls.authtoken')),
    path('api-token-auth/', obtain_auth_token),
]

# urlpatterns += staticfiles_urlpatterns()

# if settings.DEBUG:
#     urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
#     urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

The hashed-out lines didn’t have any affect.

Here’s the Repo, if it helps anyone who’s could kindly offer any help:

Thanks in advance.