我在加载css文件时遇到问题,在调用继承base_ownsite.html的index.html之后读取了css页面,css没有加载......
base_ownsite.html
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% static 'ownsite/css/style.css' %}" />
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
的index.html
{% extends 'ownsite/base_ownsite.html' %}
{% block content %}
{% if user.is_authenticated %}
<p>Jesteś zalogowany <a href='accounts/my_view'>{{ user.username }}</a></p>
<p><a href='/accounts/logout_view'>wyloguj</a></p>
{% else %}
<h2>Strona główna</h2>
<a href='/accounts/login_view'>logowanie</a>
<a href='/accounts/register_user'>rejestracja</a>
{% endif %}
{% endblock %}
的style.css
body {
background: yellow;
}
h2 {
color: red;
}
p {
color: yellow;
}
settings.py
STATIC_URL =&#39; / static /&#39;
STATICFILES_DIRS = (
"/ownsite/static",
)
我添加了目录的printcreen
答案 0 :(得分:0)
请勿对网址进行硬编码,您的问题可能在STATICFILES_DIRS中,请将其更改为:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
还要确保你有
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
位于文件顶部