Home > Blockchain >  Static File and Media Accessing issue while Deploying Django app in Production Environment
Static File and Media Accessing issue while Deploying Django app in Production Environment

Time:02-04

While deploying django app on production environment in openlitespeed server, static files and media files not found. App is woking fine in development environment in local, but after uploading it to server, static content and media files are not accessible.

I have updated my static url as follow:

STATIC_URL = '/public/static/'
STATIC_ROOT = '/home/domain.com/app/public/static

Where app is the project location. I am getting 404 for error for all static and media files:

Failed to load resource: the server responded with a status of 404 ()

When I try collectstatic I am getting following error on terminal:

django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.

I tried many options, none of the options worked. Any solution will be highly appreciated

CodePudding user response:

I assume the missing apostrophe is just missclick here in SO if it worked on development. This is how you should handle STATIC_ROOT in Django >= 4.0:

STATIC_ROOT = BASE_DIR / 'app/public/static'

Older versions:

STATIC_ROOT = os.path.join(BASE_DIR, 'app/public/static')

CodePudding user response:

You are missing inverted comma end of your code

STATIC_ROOT = '/home/domain.com/app/public/static

it should be

STATIC_ROOT = '/home/domain.com/app/public/static'

CodePudding user response:

Problem Solved:

STATIC_ROOT = BASE_DIR / 'app/public/static'

I updated static_root convention according to Django >= 4.0 and on openlitespeed server every static content should be placed inside /public folder which is mandatory rule if we do not edit default configuration. I created /public folder and moved my static and media folder. And then did the collectstatic. Problem resolved.

  •  Tags:  
  • Related