Configuration
- Python 3.6.3
- Django 2.0.1
- Bootstrap 3.3.7
- localhost:8000/static/a.jpg
create diretory static
mkdir my/static
mkdir my/static/img
cp a.jpg my/static/img/
vim my/my/settings.py
### Add STATICFILES_DIRS ###
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
startapp bs
python3 manage.py startapp bs
vim my/my/urls.py
from django.conf.urls import url,include
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^bs/', include('bs.urls')),
]
vim my/bs/urls.py
from django.shortcuts import render
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.bs_bs0, name="bootstrap_bs0"),
url(r'^bs1$', views.bs_bs1, name="bootstrap_bs1"),
]
vim my/bs/views.py
from django.shortcuts import render
def bs_bs0(request):
return render(request, "bs0.html")
def bs_bs1(request):
return render(request, "bs1.html")
vim my/my/settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
##'DIRS': [],
### Add: static/html ###
'DIRS': [os.path.join(BASE_DIR, 'static'),],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
mkdir my/static/html
vim my/static/bs0.html
<!DOCTYPE html>
<html>
<head>
<title>Hello world! This is Blog! Bootstrap</title>
</head>
<body>
<h1>My first page: bs_home.html</h1>
</body>
</html>
cp