简体   繁体   English

Django管理静态文件404

[英]Django admin static files 404

I'm using Django version 1.10. 我正在使用Django 1.10版。 Project work fine on Debug = True, but when I set it to False is not. 项目在Debug = True上工作正常,但是当我将其设置为False时则没有。 Django just can't find static files. Django只是找不到静态文件。

My Django settings looks like: 我的Django设置如下:

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 还有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.ini文件

[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. 我还使用了python manage.py collectstatic,它收集了所有内容,但仍然无法正常工作。

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. 这是Django设计。 A quote from the docs for Static file development view : 静态文件开发视图 文档中的引文:

This view will only work if DEBUG is True. 仅当DEBUG为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. 如果您将DEBUG=False设置DEBUG=False您可能要生产。 If so, your static files must be served by a webserver (eg. Nginx, Apache etc). 如果是这样,您的静态文件必须由网络服务器(例如Nginx,Apache等)提供。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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