问题
With debug turned off Django won't handle static files for you any more - your production web server.
Implement this code inside your project:
settings.py
STATIC_DIR=os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
if DEBUG:
STATICFILES_DIRS = [
STATIC_DIR,
]
else:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
...
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,document_root=settings.STATICFILES_DIRS)
来源:https://stackoverflow.com/questions/66132733/how-to-run-static-file-when-debug-is-false