[英]Django TemplateSyntaxError - 'staticfiles' is not a registered tag library
[英]Django 3 TemplateSyntaxError: 'css/bootstrap.min.css' is not a registered tag library
我將bootstrap.min.css
8CBA22E28EB17B5F5C6AE2A266AZ 添加到我的簡單 Django v3 項目中。 所以我的home.html
是這樣的:
{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Boards</title>
<link rel="stylesheet" href="{% load static '/css/bootstrap.min.css' %}">
</head>
<body>
<div class="container">
<ol class="breadcrumb my-4">
<il class="breadcrumb-item active">Boards</il>
</ol>
<table class="table">
<thead class="thead-dark">
<tr>
<th>Boards</th>
<th>Posts</th>
<th>Topics</th>
<th>Last Post</th>
</tr>
</thead>
<tbody>
{% for each in boardlist %}
<tr>
<td>
{{ each.name }}
<small class="text_muted d-block">{{ each.description }}</small>
</td>
<td class="align-middle">0</td>
<td class="align-middle">0</td>
<td></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>
我的項目結構是:
$ tree -I "*.pyc" forum/
forum/
├── boards
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ ├── models.py
│ ├── __pycache__
│ ├── static
│ │ └── css
│ │ └── bootstrap.min.css
│ ├── templates
│ │ ├── home.html
│ │ └── home.html.bak
│ ├── tests.py
│ └── views.py
├── database
│ └── db.sqlite3
├── forum
│ ├── asgi.py
│ ├── __init__.py
│ ├── __pycache__
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── manage.py
10 directories, 18 files
但是最后當我運行項目時,出現以下錯誤:
django.template.exceptions.TemplateSyntaxError: ''/css/bootstrap.min.css'' is not a registered tag library. Must be one of:
admin_list
admin_modify
admin_urls
bootstrap_tags
cache
i18n
l10n
log
static
tz
我對我的setting.py
懷疑態度:
STATICFILES_DIRS = [
#os.path.join(BASE_DIR, "boards","static"),
os.path.join(BASE_DIR, "static"),
'/var/www/static/',
]
# STATIC_URL = 'boards/static/'
STATIC_URL = '/static/'
但是所有的可能性都不適合我。
改變這個
<link rel="stylesheet" href="{% load static '/css/bootstrap.min.css' %}">
至
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.