繁体   English   中英

加载 static 文件时,Django 在“模板”中查找

[英]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 来自 VS Code 的错误消息

谁能告诉我我做错了什么?

你的代码中有一个类型在 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM