我有一个使用开发服务器manage.py runserver
在本地计算机上运行的Django项目,在将其部署到虚拟机中之前,我尝试使用Uvicorn运行它。因此,在我的虚拟环境中,我安装了uvicorn
并启动了服务器,但是正如您在下面看到的那样,它找不到Django静态CSS文件。
(envdev) user@lenovo:~/python/myproject$ uvicorn myproject.asgi:application --port 8001
Started server process [17426]
Waiting for application startup.
ASGI 'lifespan' protocol appears unsupported.
Application startup complete.
Uvicorn running on http://127.0.0.1:8001 (Press CTRL+C to quit)
INFO: 127.0.0.1:45720 - "GET /admin/ HTTP/1.1" 200 OK
Not Found: /static/admin/css/base.css
Not Found: /static/admin/css/base.css
INFO: 127.0.0.1:45720 - "GET /static/admin/css/base.css HTTP/1.1" 404 Not Found
Not Found: /static/admin/css/dashboard.css
Not Found: /static/admin/css/dashboard.css
INFO: 127.0.0.1:45724 - "GET /static/admin/css/dashboard.css HTTP/1.1" 404 Not Found
Not Found: /static/admin/css/responsive.css
Not Found: /static/admin/css/responsive.css
INFO: 127.0.0.1:45726 - "GET /static/admin/css/responsive.css HTTP/1.1" 404 Not Found
Uvicorn有一个选项--root-path
,所以我尝试指定这些文件所在的目录,但是仍然存在相同的错误(路径正确)。我该如何解决这个问题?
答案 0 :(得分:5)
当不与内置开发服务器一起运行时,您将需要
使用the classic staticfile deployment procedure which collects all static files into some root,并且预期将为它们提供静态文件服务器。 Uvicorn似乎不支持静态文件服务,因此您可能还需要其他东西(例如,https://www.uvicorn.org/deployment/#running-behind-nginx)。
(非常,非常不可取!)have Django serve static files like it does in dev