不能 link css 文件到 django
can not link css file to django
这是我链接 CSS 文件的 html 文件
{% load static %}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>ShairuFitness</title>
<script defer src="https://use.fontawesome.com/releases/v5.0.7/js/all.js"></script>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="{% static 'fit/css/base.css' %}">
这是settings.py个文件
STATIC_URL = '/static/'
STATICFILE_DIRS = [os.path.join(BASE_DIR,'static'),]
这是文件的位置
static
->fit
->css
->base.css
错误
[10/Aug/2020 20:50:31] "GET /static/fit/css/base.css HTTP/1.1" 404 1674
试试这个设置:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT
用于设置静态文件的路径。您可以在 the official doc.
上阅读更多内容
这是我链接 CSS 文件的 html 文件
{% load static %}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>ShairuFitness</title>
<script defer src="https://use.fontawesome.com/releases/v5.0.7/js/all.js"></script>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="{% static 'fit/css/base.css' %}">
这是settings.py个文件
STATIC_URL = '/static/'
STATICFILE_DIRS = [os.path.join(BASE_DIR,'static'),]
这是文件的位置
static
->fit
->css
->base.css
错误
[10/Aug/2020 20:50:31] "GET /static/fit/css/base.css HTTP/1.1" 404 1674
试试这个设置:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT
用于设置静态文件的路径。您可以在 the official doc.