简体   繁体   中英

Django admin static files 404

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.

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).

检查whitenoice库,它非常适合开发和生产环境,为Python Web应用程序提供了彻底简化的静态文件服务

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM