Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - CSS File Not Loading In Production (Debug: False) [duplicate]

Current error (Debug=False)

"[16/Jan/2018 15:18:42] "GET /static/style.css HTTP/1.1" 404 90"

Web site loads but broken formatting because CSS file not loaded

Logging:

On the CMD prompt it says

"[16/Jan/2018 15:49:05] "GET /beginners/ HTTP/1.1" 200 3760
[16/Jan/2018 15:49:05] "GET /static/style.css HTTP/1.1" 404 90
"

I'm not sure why this isn't working: my style.css is located in my static folder, and the static folder is the same folder as manage.py

When I set Debug = True, I reload the page and it works fine - my static folder is active and I get no static error:

[16/Jan/2018 15:58:11] "GET /beginners/? HTTP/1.1" 200 3759
[16/Jan/2018 15:58:11] "GET /static/style.css HTTP/1.1" 200 5014

Please help!!

STATIC_URL = '/static/'
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]

DEBUG = True

ALLOWED_HOSTS = ['127.0.0.1']

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
like image 604
math_is_for_nerds Avatar asked Nov 25 '25 00:11

math_is_for_nerds


1 Answers

You are using Django's development server with Debug=False. Django will not serve static content when Debug is False.

Django development server is not intended to be used in production.

You will need a Web Server which will serve your static content (or put it on a CDN)

Common deployment styles used with Django are

nginx -> uwsgi -> django


apache -> mod_wsgi -> django


There's also gunicorn which is relatively easier to set up.

like image 142
at14 Avatar answered Nov 27 '25 14:11

at14



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!