如何在Uvicorn Web服务器上运行Django?

时间:2020-05-13 09:08:10

标签: python django uvicorn

我有一个使用开发服务器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,所以我尝试指定这些文件所在的目录,但是仍然存在相同的错误(路径正确)。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:5)

当不与内置开发服务器一起运行时,您将需要