Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Static files 404

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

like image 516
KindOfGuy Avatar asked Oct 09 '12 22:10

KindOfGuy


People also ask

What are the static files in Django?

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.

What is white noise in 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)

Can Gunicorn serve static files?

Gunicorn is meant to serve dynamic content, it should not be used to serve static files. We will add nginx to serve static files.


2 Answers

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'), ) 
like image 135
Amar Kamthe Avatar answered Sep 28 '22 19:09

Amar Kamthe


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.

like image 20
Arthur Tacca Avatar answered Sep 28 '22 21:09

Arthur Tacca