*ํ
ํ๋ฆฟ ์์
์ฌ๋ฌ๊ฐ์ ๋น์ทํ ํ์ด์ง๋ฅผ ๋ง๋ค๋, ๋ฐ๋ณต๋
ธ๋์ ์ค์ฌ์ค๋ค.
*base.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="/static/bootstrap.min.css"/>
<title>Hello, world!</title>
</head>
<body>
<br>
<div class= "container">
<!-- ํ
ํ๋ฆฟ ์์ ! -->
{% block contents %}
{% endblock %}
</div>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>
๋ผ๋๊ฐ ๋๋ ๋ถ๋ชจํ๊ทธ๋ค์ ๋จ๊ฒจ๋๊ณ , ์ฝํ
์ธ ๊ฐ ๋ค์ด๊ฐ๋ถ๋ถ์ {% block contents %}, {% endblock %} ์ ๋ฃ์ด์ค๋ค.
*index.html
{% extends "base.html" %}
{% block contents %}
<div class = "raw">
<div class = "col-12" >
<div class = "col-12 text-center">
<h1>๋ก๊ทธ์ธ</h1>
<br><br>
</div>
<form method = "POST">
{% csrf_token %}
<div class="form-group">
<label for="password">๋น๋ฐ๋ฒํธ</label>
<input type="password"
name = "password"
class="form-control" id="password" placeholder="๋น๋ฐ๋ฒํธ๋ฅผ ์
๋ ฅํ์ธ์">
</div>
<span style="color:red;"><strong>{{ error }}</strong> </span>
<button type="submit" class="btn btn-primary">๋ก๊ทธ์ธ</button>
</form>
{% endblock %}
{% extends "base.html" %} ๋ก ์์๊ด๊ณ๋ฅผ ์ค์ ํด์ฃผ๊ณ , {%block contents%} ๋ด๋ถ์ baseํ์ผ์์ ๋น์๋์๋ ๋ถ๋ถ์ ๋ฃ์ด์ฃผ๋ฉด ๋๋ค.
*์ ์ ํ์ผ (static )
1. ํ๋ก์ ํธ ํด๋ ํ์์ statics ํด๋๋ฅผ ๋ง๋ค์ด ์ค๋ค.
2. settings.py ์ ์๋ ๊ฒฝ๋ก๋ฅผ ์ถ๊ฐํด์ค๋ค.
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'), # base_dir์ ํ๋ก์ ํธ ํด๋
]
3. htmlํ์ผ์ ์ฐ๊ฒฐํด์ค๋ค.
<link rel="stylesheet" href="/static/bootstrap.min.css"/>
๊ฐ๋จํ ํ์ด์ง๋ผ๋ฉด ๋ถํธ์ค์์น์ cssํ์ผ์ ๋ฐ๋๊ฒ ์ข์๊ฒ ๊ฐ๋ค.
(https://bootswatch.com/)