【发布时间】:2020-10-17 13:36:39
【问题描述】:
首先:我知道有很多用户问题,但他们都没有解决我的问题,所以我希望在这里最好。我的 django 无法访问静态文件,我得到了 404。
基础设施:安装了 django 和 apache 反向代理到 localhost:8000 的公共可访问服务器。 (它不是 apache 问题。当本地转发 8000 端口时,此问题仍然存在)。
目录列表:
/var/twirps
.
|-- assets
| |-- admin
| | |-- css
| | | `-- vendor
| | | `-- select2
| | |-- fonts
| | |-- img
| | | `-- gis
| | `-- js
| | |-- admin
| | `-- vendor
| | |-- jquery
| | |-- select2
| | | `-- i18n
| | `-- xregexp
| |-- css
| | `-- images
| |-- js
| |-- sass
| | `-- libs
| `-- webfonts
|-- blockmatrix
| |-- __pycache__
| `-- migrations
|-- static
| |-- css
| | `-- images
| |-- js
| |-- sass
| | `-- libs
| `-- webfonts
|-- templates
`-- twirps
`-- __pycache__
settings.py:
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
我的静态文件声明 index.html(在模板文件夹中):
{% load static %}
<link rel="stylesheet" href="{% static 'static/css/main.css' %}" />
我也已经做了python3 manage.py collectstatic
静态文件仍然无法加载,我在 django 服务器日志中看到 404 错误。请在这里帮助我。
【问题讨论】:
标签: python python-3.x django django-templates