Reputation: 383
I am deploying my Django project on vercel
This is my vercel.json
file
{
"version": 2,
"builds": [
{
"src": "event_management/wsgi.py",
"use": "@vercel/python",
"config": {"maxLambdaSize": "15mb", "runtime": "python3.9"}
},
{
"src": "build_files.sh",
"use": "@vercel/static-build",
"config": {
"distDir": "staticfiles_build"
}
}
],
"routes": [
{
"src": "/static/(.*)",
"dest": "/static/$1"
},
{
"src": "/(.*)",
"dest": "event_management/wsgi.py"
}
]
}
my settings.py
STATIC_URL = 'static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_build', 'static')
everything works fine but when I open the admin panel one CSS file static/admin/css/base.css
is throwing 404 error all the other static files are loading fine
Here is the admin panel link.
the base.css is even listed in Vercel static Assets
You can also check the file is present on the directory listing here
here is my github repo link the code is in main branch
Upvotes: 0
Views: 528
Reputation: 11
I got mine to work, OMG! It was a nightmare, but I'm just leaving the solution here in case anyone else encounters this issue. You don't have to add the static files in your vercel.json, it will find it automatically it turns out!
vercel.json
`{
"builds": [
{
"src": "project/wsgi.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "project/wsgi.py"
}
]
} `
wsgi file:
import os
from django.core.wsgi import get_wsgi_application
from whitenoise import WhiteNoise
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
application = get_wsgi_application()
application = WhiteNoise(application, root=os.path.join(os.path.dirname(__file__), 'static'))
app = application # added for django vercel
`
I hope this helps any one else who encounters this issue!
Upvotes: 1
Reputation: 17
After inspecting the logs and the files present, I can see all works fine, the css file for the base.css
for the admin panel returned a response 300
.
enter image description here
So, the solution is all good.
just incase you left it out, it will good to install and configure white noise.
Upvotes: 0