5

I'm using Django version 1.10. Project work fine on Debug = True, but when I set it to False is not. Django just can't find static files.

My Django settings looks like:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'master',
'update',
]

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    )

STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = '/static/'
STATICFILES_DIRS = ()

And the urls.py

from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^master/', include('master.urls')),
    url(r'^update/', include('update.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

uwsgi.ini file

[uwsgi]
chdir           = %v
virtualenv      = %v/py
module          = go_conf.wsgi
master          = true
http            = :8000
vacuum          = true

buffer_size     = 64k
max-requests    = 100
daemonize       = %v/log.txt

I aslo used python manage.py collectstatic, and it collected everything but still not working.

I tried to solve this by reading other articles on this site, but nothing really worked for me.

Hope, that someone will at last help.

Mr. Nobody
  • 165
  • 2
  • 8
  • 2
    With debug turned off Django won't handle static files for you any more - your production web server (Apache or something) should take care of that. Ref : http://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail – Rahul K P Feb 25 '17 at 15:30
  • 1
    Possible duplicate of [Why does DEBUG=False setting make my django Static Files Access fail?](http://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail) – Rahul K P Feb 25 '17 at 15:30
  • Yes, I noticed that. However even when I'm using uwsgi this doesn't work. I edited my question and added uwsgi.ini file. – Mr. Nobody Feb 25 '17 at 16:22

2 Answers2

12

This is the Django desing. A quote from the docs for Static file development view:

This view will only work if DEBUG is True.

That’s because this view is grossly inefficient and probably insecure. This is only intended for local development, and should never be used in production.

If you are setting DEBUG=False you are probably going to make it production. If so, your static files must be served by a webserver (eg. Nginx, Apache etc).

abcdn
  • 1,397
  • 14
  • 15
  • I just used uwsgi with http parameter. On my vps I have installed nginx. – Mr. Nobody Feb 25 '17 at 16:25
  • If you want just uwsgi, then probaply `--static-map /static=/var/www/static` is the option for you. Details here: http://uwsgi-docs.readthedocs.io/en/latest/StaticFiles.html – abcdn Feb 25 '17 at 16:40
1

check the whitenoice library, it works great for development and production environment Radically simplified static file serving for Python web apps

Dmitrij
  • 116
  • 1
  • 7