when the project is deployed shows this error here is my settings.py:
import os
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
DEBUG = True
ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [
'me',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
"whitenoise.runserver_nostatic",
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
"whitenoise.middleware.WhiteNoiseMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'Matheus.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR, 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'Matheus.wsgi.application'
...
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / "staticfiles" / "static"
if DEBUG:
STATICFILES_DIRS=['staticfiles']
STATIC_ROOT = None
else:
STATICFILES_DIRS=[]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
# Whitenoise Storage Class - Apply compression but don’t want the caching behaviour
STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
here is my vercel.json:
{
"version": 2,
"builds": [
{
"src": "Matheus/wsgi.py",
"use": "@vercel/python",
"config": {
"maxLambdaSize": "15mb",
"runtime": "python3.12"
}
},
{
"src": "build.sh",
"use":"@vercel/static-build",
"config":{
"distDir": "staticfiles"
}
}
],
"routes": [
{
"src":"/static/(.*)",
"dest":"/static/$1"
},
{
"src": "/(.*)",
"dest": "Matheus/wsgi.py"
}
]
}
here is my build.sh:
#!/bin/bash
# Update pip
echo "Updating pip..."
python3.12 pip install -U pip
# Install dependencies
echo "Installing project dependencies..."
python3.12 -m pip install -r requirements.txt
# Make migrations
echo "Making migrations..."
python3.12 manage.py makemigrations --noinput
python3.12 manage.py migrate --noinput
#Install whitenoise
echo Installing white noise..."
python3.12 manage.py whitenoise
# Collect staticfiles
echo "Collect static..."
python3.12 manage.py collectstatic --noinput --clear
echo "Build process completed!"```
wsgi config :
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Matheus.settings')
application = get_wsgi_application()
# vercel config
app = application # add this line.
https://github.com/Matheus-Dimon/me/tree/teste
I want to a config to change that can make the deploy serves the staticfiles.
i found the solution with these configs: in vercel.json i change this :
in settings.py this config:
and url.py of app put this :