无法为 django 应用程序(apache - wsgi)提供静态文件

问题描述 投票:0回答:1

我的计划名为投资组合,这是我的主页。 我在这个项目上创建了一个名为experiences的应用程序。

在开发服务器上,我可以为两者提供静态文件。但在生产中,我只能为主页(项目)提供服务,而不能为应用程序提供服务。我遇到 404 Not Found 错误。

我已经收集了。

我在每个应用程序(和项目)上都有一个静态目录。

我正在使用 apache 和 wsgi 模块。

我在设置文件中有这个conf:

STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "Portfolio/static")
]

足弓下方:

src/
|-- Experiences
|   |-- __pycache__
|   |-- migrations
|   |   `-- __pycache__
|   |-- static
|   |   `-- Experiences
|   |       |-- assets
|   |       |   |-- fonts
|   |       |   `-- img
|   |       `-- css
|   `-- templates
|       `-- Experiences
|-- Portfolio
|   |-- __pycache__
|   |-- static
|   |   `-- Portfolio
|   |       |-- assets
|   |       |   |-- fonts
|   |       |   `-- img
|   |       `-- css
|   `-- templates
|       `-- Portfolio
`-- staticfiles
    |-- Experiences
    |   |-- assets
    |   |   |-- fonts
    |   |   `-- img
    |   `-- css
    |-- Portfolio
    |   |-- assets
    |   |   |-- fonts
    |   |   `-- img
    |   `-- css
    `-- admin
python django apache mod-wsgi django-staticfiles
1个回答
0
投票

这是预料之中的,在开发中 Django 提供静态文件,但在生产中(当 debug 为 false 时)则不然,因为这会导致性能问题。

您可以在Django Docs

中查看有关如何配置静态文件的官方文档

如果您想要更简单的解决方案,您可以尝试whitenoise

© www.soinside.com 2019 - 2024. All rights reserved.