javascript - 如何在 Django 中使用 css 和 javascript 的静态文件夹?

标签 javascript python html css django

我是 django 框架的新手。我创建了简单的欢迎页面,现在我想在我的元素中包含 css 文件。我无法在元素中应用 css 文件。我收到类似“NetworkError: 404 NOT”的错误 找到 -/static/css/hai.css"

my project structure 这是我的元素结构

设置.py

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
STATIC_URL = '/static/'
TEMPLATE_DIRS=(
os.path.join(os.path.dirname(BASE_DIR),"static","templates"),
)
if DEBUG:
  MEDIA_URL='/media/'
  STATIC_ROOT=os.path.join(os.path.dirname(BASE_DIR),"static","static-only")
  MEDIA_ROOT=os.path.join(os.path.dirname(BASE_DIR),"static","media")
  STATICFILE_DIRS=(
  os.path.join(os.path.dirname(BASE_DIR),"static","static"),
  )

url.py

if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

base.html

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

我尝试点击链接,但无法应用CSS https://www.youtube.com/watch?v=8t80DMAAps8

最佳答案

我认为这只是一个拼写错误。您需要在 STATICFILE 之后放置一个 S 因此它应该如下所示:

STATICFILES_DIRS=(
  os.path.join(os.path.dirname(BASE_DIR),"static","static"),
  )

希望这会成功。

关于javascript - 如何在 Django 中使用 css 和 javascript 的静态文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26653721/

相关文章:

javascript - Gulp 'Open' 任务未正确执行

javascript - 集合上的 jQuery 选择器

Python 一行代码(将 perl 转换为 pyp)

python 安装 numpy 和 matplotlib 异常(使用 pip)

javascript - jQuery:如何从多个元素获取文本并将其打印在多行上?

javascript - d3 工具提示 - 在 d3 折线图中为工具提示添加 div

javascript - 更新 AngularJS 服务中的 $scope 对象不会更新 View

javascript - Moment.js,如何在不更改时区的情况下更改日期格式?

python - python简单的if条件问题

javascript - 默认情况下在 html 文本框内仅显示小数点后 4 位数字的简单方法是什么