Configuration
- Python 3.6.3
- Django 2.0.1
- Bootstrap 3.3.7
- localhost:8000/static/img/a.jpg
vim my/my/settings.py
Add STATICFILES_DIRS
mkdir my/static
mkdir my/static/img
cp a.jpg my/static/img
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/'
### Add STATICFILES_DIRS ###
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
- localhost:8000/bs/bs1
First page for bootstrap 3.3.7
vim my/bs/urls.py
from django.shortcuts import render
# Create your views here.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.bootstrap_title, name="bootstrap_home"),
### Add bs1 ###
url(r'^bs1$', views.bs_bs1, name="bootstrap_bs1"),
]
vim my/bs/views.py
def bs_bs1(request):
return render(request, "bs/bs1.html")
cp bootstrap & jquery
cp bootstrap-3.3.7-dist my/static/
cp jquery my/static/
vim my/templates/bs/bs1.html
{% load static %}
<link rel="stylesheet" href="{% static 'bootstrap-3.3.7-dist/css/bootstrap.min.css' %}">
<script src="{% static 'jquery/jquery-3.2.1.min.js' %}"></script>
<script src="{% static 'bootstrap-3.3.7-dist/js/bootstrap.min.js' %}"></script>
{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>Hello world! This is Blog! Bootstrap 实例</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{% static 'bootstrap-3.3.7-dist/css/bootstrap.min.css' %}">
<script src="{% static 'jquery/jquery-3.2.1.min.js' %}"></script>
<script src="{% static 'bootstrap-3.3.7-dist/js/bootstrap.min.js' %}"></script>
</head>
<body>
<table class="table table-hover">
<caption>悬停表格布局</caption>
<thead>
<tr>
<th>名称</th>
<th>城市</th>
<th>邮编</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tanmay</td>
<td>Bangalore</td>
<td>560001</td>
</tr>
<tr>
<td>Sachin</td>
<td>Mumbai</td>
<td>400003</td>
</tr>
<tr>
<td>Uma</td>
<td>Pune</td>
<td>411027</td>
</tr>
</tbody>
</table>
</body>
</html>