简体   繁体   中英

django_bootstrap5 not formatting anything

I'm trying to get basic bootstrap formatting working in a django app, and installed django_bootstrap5 to do so. No formatting, however, is getting applied to any of the pages.

Here's the various pages:

base.html:

<!DOCTYPE html>
{% load django_bootstrap5 %}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>
        {% block title %}
        {% endblock %}
    </title>
</head>
<body>
<div class="container">
    {% block body %}
    {% endblock %}
</div>
</body>
</html>

I extend this in a simple index page:

<!DOCTYPE html>
{% extends 'base.html' %}
{% load django_bootstrap5 %}

{% block title %}
  Home
{% endblock %}

{% block body %}
<h1>Hello World</h1>
{% endblock %}

Hello World, however, is not showing up in a container.

This is also failing on a form page:

<!DOCTYPE html>
{% extends 'base.html' %}
{% load django_bootstrap5 %}

{% block body %}
<div class="container">
    <h1>Sign Up</h1>
    <form method="POST">
        {% csrf_token %}
        {% bootstrap_form form %}
        <input type="submit" value="Sign Up" class="btn btn-default">
    </form>
</div>
{% endblock %}

The form is neither in a bootstrap container, nor does it have any styling at all. What am I missing here? Do you need to also load the bootstrap files by cdn or download them and add them to static when using django_bootstrap5 ? That makes things work, but it seems like it defeats the purpose of installing via pip. Thank you.

Tracked it down in the source code: for use of the django_bootstrap5 package you are supposed to include bootstrap via cdn or by downloading the local files to static, in addition to installing the django_bootstrap5 package.

I caught it in a resolved issue on github here , here's the relevant line:

Hi, Just a tiny error on the core.py file that I forgot to fix on loading the app in a new environment, the final 's' is missing on line 13:

        "url": "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.j",
Rather than:

        "url": "https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js",
Easy enough to fix but thought it might be handy to prevent any panic moments!

In conclusion, install bootstrap as well as django_bootstrap5 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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