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
This is the working solution for static/media/template access in django for windows,
settings.py
in Django you have one more advantage for your templates and it's you can link statics like this and maybe this is your problem!
its better to use
and its also easier to know more about, i refer to https://docs.djangoproject.com/en/1.11/intro/tutorial06/
If you are running this on a web server are you copying the static files to a public accessible folder? For example:
Then you can use this post Django static Files and copy the static files to the public accessible folder using manage.py
Hope that helps!
from comments above - run this
I simply renamed my static folder to staticfiles and all was well. (I'm on osx + django 1.x)
use insecure mode may not hurt if you're on local dev box - otherwise you may still get 404 errors.
UPDATE
actually digging into settings.py found the infringing line.
For me this turned out to be caused by setting debug to false in
settings.py
. A workaround is to pass the--insecure
switch torunserver
, 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.I simply added the equivalent of
to get this working. Of course, replace
absolute_path_to_project
with your actual path and, if necessary, add the drive letter.