gpt4 book ai didi

css - 无法在 Django 中加载 CSS 文件

转载 作者:行者123 更新时间:2023-11-28 13:12:18 25 4
gpt4 key购买 nike

我正在使用 Ubuntu 和 Django 1.3.7。以下是各种相关设置:

我的目录结构:

mysite/
manage.py
settings.py
__init__.py
urls.py
myapp/
__init__.py
forms.py
models.py
views.py
templates/
index.html
home.html
static/
common.css
...
...

我的settings.py 文件:

import os.path
SETTINGS_ROOT = os.path.dirname(__file__)
INSTALLED_APPS = (
...
...
'django.contrib.staticfiles'
)
STATIC_ROOT = os.path.join(SETTINGS_ROOT, "static/")
STATIC_URL = '/static/'

在我的模板 html 文件中:

<link rel="stylesheet" type="text/css" href="/static/bootstrap/css/bootstrap.css">

仍然,页面不显示任何图像、css 或 js 文件。我已经阅读了文档。但没有任何帮助。为了使文件运行,我还需要包含/修改什么?

最佳答案

STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/path/to/your/project/assets',
)

关于css - 无法在 Django 中加载 CSS 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15369003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com