我将 Docker Compose 与将静态文件夹复制到 /static 的 Dockerfile 一起使用:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install --upgrade pip && pip install -r requirements.txt
COPY static /static/
COPY . /code/
在我的设置文件中,我使用:
if env == "dev":
DEBUG = True
else:
DEBUG = False
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
X_FRAME_OPTIONS = "DENY"
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
STATICFILES_DIRS = [
# os.path.join(BASE_DIR, "static/"),
'/static'
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
静态文件在 dev 中工作,但是当我将 env 更改为 prod 时,我开始收到 404 错误。
所以你看到问题了吗?