I can't get my static files to come up. I've tried various settings and directory configurations and so on, but they just turn up as 404s. I have debug_toolbar installed so know that STATIC_URL is reaching my request context.
Directory structure showing /static (I have also placed the directory inside of the meals app folder, and users, just to try it out.
/mealmate /mealmate /meals /static /css /bootstrap.min.css /templates /users
Settings.py (a few important settings though I've experimented with a variety of other ones):
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media/') STATIC_URL = '/static/' INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', ) WSGI_APPLICATION = 'mealmate.wsgi.application'
In base.html rendered
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
Any ideas? Thanks
Websites generally need to serve additional files such as images, JavaScript, or CSS. In Django, we refer to these files as “static files”. Django provides django.
Project description WhiteNoise works with any WSGI-compatible app but has some special auto-configuration features for Django. WhiteNoise takes care of best-practices for you, for instance: Serving compressed content (gzip and Brotli formats, handling Accept-Encoding and Vary headers correctly)
Gunicorn is meant to serve dynamic content, it should not be used to serve static files. We will add nginx to serve static files.
This is the working solution for static/media/template access in django for windows,
settings.py
import os.path STATIC_ROOT = '' STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join('static'), )
For me this turned out to be caused by setting debug to false in settings.py
. A workaround is to pass the --insecure
switch to runserver
, but the real solution is to use a proper web server to serve the static files. See the answers to this question for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With