[英]Django looks in `templates` when loading static file
I am new to Django and I have the following issue: when I try lo link my layout.html
to styles.css
Django looks in the wrong place. layout.html
代码如下:
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href="{% static 'encyclopedia/styles.css' %}" rel="stylesheet">
</head>
我的encyclopedia
目录结构如下:
├── db.sqlite3
├── encyclopedia
│ ├── __init__.py
│ ├── __pycache__
│ ...
│ ├── models.py
│ ├── static
│ │ └── encyclopedia
│ │ └── styles.css
│ ├── templates
│ │ └── encyclopedia
│ │ ... └── search.html
│ ├── tests.py
│ ├── urls.py
│ ├── util.py
│ └── views.py
├── manage.py
└── wiki
我确实检查了 dir wiki
中的settings.py
文件,它确实有一个: STATIC_URL = '/static/'
行。 然而 Django 根据以下错误消息继续查看templates
:
谁能告诉我我做错了什么?
你的代码中有一个类型在 href 中(% 右丢失)
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href="{% static 'encyclopedia/styles.css' %}" rel="stylesheet">
</head>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.