Django 3 TemplateSyntaxError:'css/bootstrap.min.css'不是已注册的标记库

2024-04-24 12:39:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我将bootstrap.min.css添加到我的简单DjangoV3项目中。所以我的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

但在运行project的最后,我出现了以下错误:

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

我对我的{}表示怀疑,我有:

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/'

但所有的可能性都不适合我


Tags: pyhomeadminhtmltablestaticbootstrapmin