我知道有很多类似的问题,但我找不到适合我的情况:
我在单个 docker 容器中使用 django (2.1.7) 以及gunicorn 和 nginx(我们在工作中使用的基础设施的要求),但在管理菜单上遇到了问题。当本地执行并访问http://localhost:8080/admin/页面时,无需使用 css 即可呈现页面。
经过一番挖掘,我发现 nginx 实际上是在提供文件服务。例如,我可以http://localhost:8080/static/admin/css/base.css在浏览器中访问并加载相关文件。我的静态目录也BASEDIR包含所有预期的文件......
我不知道如何继续进一步调查。所有相关问题的配置似乎都有缺陷STATIC_ROOT,忘记了collectstatic命令或误用alias了 nginx 配置中的命令。所有这些似乎都对我有用......
我觉得我错过了一些非常基本的东西。你们有人有想法吗?感谢您的帮助!
下面是我的配置文件
settings.py::
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 2.1.7.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = …Run Code Online (Sandbox Code Playgroud)