Django Bootstrap4 ์—ฐ๋™

2021. 5. 23. 14:17ใ†Backend/๐Ÿ Python

1. ์šฐ์„  Bootstrap ๊ณต์‹ํ™ˆํŽ˜์ด์ง€์—์„œ CSS CDN์„ copy ํ•ฉ๋‹ˆ๋‹ค.

https://getbootstrap.com/docs/5.0/getting-started/introduction/

 

Introduction

Get started with Bootstrap, the world’s most popular framework for building responsive, mobile-first sites, with jsDelivr and a template starter page.

getbootstrap.com

 

 

copy ํ•œ css cdn ์„ ์žฅ๊ณ  ํ…œํ”Œ๋ฆฟ ๋‚ด๋ถ€์— ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•ด์ค๋‹ˆ๋‹ค.

<head>
    <meta charset="UTF-8">
    <title>Title</title>

    {#    bootstrap #}
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"
          integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">

</head>

 

2. bootstrap4 library๋ฅผ ๋‹ค์šด๋กœ๋“œ ๋ฐ›๊ฒ ์Šต๋‹ˆ๋‹ค.

terminal์— pip install django-bootstrap4 ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

 

๋‹ค์Œ์œผ๋กœ settings.py ํŒŒ์ผ์˜ Installed_apps์— ์•„๋ž˜์ฒ˜๋Ÿผ ๋“ฑ๋กํ•ด์ค๋‹ˆ๋‹ค.

Settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'bootstrap4',  # ์ถ”๊ฐ€
]

 

3.  load bootstrap 4  =>  {% load bootstrap4 %}

{% load bootstrap4 %}  # bootstarp4 ๋กœ๋“œ
    <div style="text-align: center; max-width: 500px; margin: 4rem auto">
        <div>
            <h4>LOGIN</h4>
        </div>
        <div>
            <form method="post">
                {% csrf_token %}
                {% bootstrap_form form %}
                <input type="submit" class="btn btn-dark rounded-pill col-6 mt-3">
            </form>
        </div>
    </div>

 

์œ„ ์ฝ”๋“œ์˜ input ํƒœ๊ทธ์˜ ํด๋ž˜์Šค๋Š” bootstrap์˜ ํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›์„ ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

๊น”๋”ํ•œ UI๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.