使用这些设置,django会显示存储在项目NeoRecApp
的应用NeoRec
的静态目录中的文件404.png DEBUG=True
,否则它不会显示debug设置为false。
(设置STATIC_ROOT
后,我运行python manage.py collectstatic
,将文件移至新创建的' NeoRecApp / static'。
settings.py
DEBUG = False
#DEBUG = True
ALLOWED_HOSTS = ["*"]
STATIC_URL = 'static/'
STATIC_ROOT = 'NeoRecApp/static/'
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'NeoRecApp',
)
urls.py
from django.conf.urls import include, url
from django.contrib import admin
from django.conf.urls.static import static
import settings
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
答案 0 :(得分:0)
我在docs上阅读了更多内容后发现,DEBUG标志设置为运行Django的测试服务器。因此,如果DEBUG = False,则Django的manage.py runserver
解决方案不会为静态文件提供服务,之后我们有两个选项 -