Django bootstrap4

Django にて bootstrap4 を実装する

pip を使ったインストール

$ pip install django-bootstrap4
~~~
Successfully installed django-bootstrap4-2.3.1

settings.py の設定

settings.py の INSTALLED_APPS に追記する

INSTALLED_APPS = [
    ~~~
    'bootstrap4',
    ~~~
]

実装方法

bootstrap4 ライブラリをロードして bootstrap_* タグを使用します。

# Example template
{# Load the tag library #}
{% load bootstrap4 %}

{# Load CSS and JavaScript #}
{% bootstrap_css %}
{% bootstrap_javascript jquery='full' %}

{# Display django.contrib.messages as Bootstrap alerts #}
{% bootstrap_messages %}

{# Display a form #}
<form action="/url/to/submit/" method="post" class="form">
  {% csrf_token %}
  {% bootstrap_form form %}
  {% buttons %}
    <button type="submit" class="btn btn-primary">
      Submit
    </button>
  {% endbuttons %}
</form>

{# Read the documentation for more information #}

Template tags and filters

Was this helpful?

1 / 0

コメントを残す 0

Your email address will not be published.