我是 Django 新手,但负责该项目的前端工作。我一直在研究如何准确加载 css 文件,但我发现这些方法不起作用。这是 .html 文件布局:
{% load static %}
<html>
<head>
<title class="title"> NHSEE Homepage </title>
<!--<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"> -->
<link rel="stylesheet" href="{% static 'css/homepage.css' %}">
</head>
<body>
<div class="container">
<h1> NHSEE </h1>
<a class="btn btn-1" href="/judges">Judges</a>
<br>
<a href="{% url 'students' %}">Students</a>
<br>
<a class="btn btn-1" href={% url 'scoring-sheet' %}>Scoring Sheet</a>
<br>
<a href="/students">Students</a>
<br>
<a href="/projects">Projects</a>
</div>
Here is the layout of the files (not sure if its where I'm putting the files that causing the issue)
Any help is greatly appreciated. Its very frustrating as I've done frontend work professionally before and can't get a stupid css file to show up.
EDIT: The settings.py file
所以,首先你需要有STATICFILES_DIRS
在你的settings.py
:
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'assets')]
然后继续移动你的所有assets(css、js、fonts...)到名为的目录assets
beside manage.py
(不在您的应用程序内)
举个例子,假设你有assets/css/home_page.css
;你应该使用{% static 'css/home_page.css' %}
在您的模板中访问它(省略assets
目录)。
这就是基本思想,您可以根据需要命名这些目录。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)