Django不显示调试True的图像

时间:2021-08-02 20:25:49

With these settings, django shows the file 404.png stored in static directory of the app NeoRecApp of the project NeoRec if DEBUG=True, otherwise it doesn't show if debug is set to false.

使用这些设置,django显示存储在项目NeoRec的应用程序NeoRecApp的静态目录中的文件404.png(如果DEBUG = True),否则它不显示debug是否设置为false。

(After setting STATIC_ROOT I ran python manage.py collectstatic, which moved the file to the newly created 'NeoRecApp/static'.)

(设置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)

1 个解决方案

#1


0  

I found out after reading more on the docs that DEBUG flag is set to run Django's test server. Hence, if DEBUG=False, then static files won't be served by Django's manage.py runserver solution, and we have two options thereafter-

我在阅读了更多关于文档后发现DEBUG标志设置为运行Django的测试服务器。因此,如果DEBUG = False,则Django的manage.py runserver解决方案将不会提供静态文件,此后我们有两个选项 -

  1. Deploy on a different server (Apache, Nginx,etc)
  2. 部署在不同的服务器上(Apache,Nginx等)

  3. Use this module (White noise) for serving static files.
  4. 使用此模块(白噪声)来提供静态文件。

#1


0  

I found out after reading more on the docs that DEBUG flag is set to run Django's test server. Hence, if DEBUG=False, then static files won't be served by Django's manage.py runserver solution, and we have two options thereafter-

我在阅读了更多关于文档后发现DEBUG标志设置为运行Django的测试服务器。因此,如果DEBUG = False,则Django的manage.py runserver解决方案将不会提供静态文件,此后我们有两个选项 -

  1. Deploy on a different server (Apache, Nginx,etc)
  2. 部署在不同的服务器上(Apache,Nginx等)

  3. Use this module (White noise) for serving static files.
  4. 使用此模块(白噪声)来提供静态文件。