python:3.6.5
django:2.0.5
- 文件目錄
? proMana tree -d
.
├── appMana
│ ├── migrations
│ │ └── __pycache__
│ └── __pycache__
├── proMana
│ └── __pycache__
├── static
│ ├── css
│ ├── fonts
│ └── js
└── templates
└── appMana
URL Configuration
- 設(shè)置project路由
proMana/urls
"""proMana URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include,path
urlpatterns = [
path('',include('appMana.urls')),
path('admin/', admin.site.urls),
]
- 編寫view文件
appMana/views.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse("信息管理系統(tǒng)")
def stuinfo(request):
#return HttpResponse("學(xué)生信息")
return render(request,'appMana/stuinfo.html')
def scinfo(request):
return HttpResponse("選課信息")
def courseinfo(request):
return HttpResponse("課程信息")
- 設(shè)置app內(nèi)頁(yè)面路由
appMana/urls
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('index/',views.index),
path('stuinfo/',views.stuinfo),
path('scinfo/',views.scinfo),
path('courseinfo/',views.courseinfo)
]
在模板中使用Bootstrap
- 在項(xiàng)目根目錄下建立文件夾templates音念,并創(chuàng)建所需html
? proMana tree templates
templates
├── appMana
│ └── stuinfo.html
└── base.html
1 directory, 2 files
- 修改
proMana/settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR+"/templates"], #修改這一條
'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',
],
},
},
]
- 在根目錄下建立靜態(tài)資源文件夾static
? proMana tree static -d
static
├── css
├── fonts
└── js
- 在Django中引用Bootstrap模版
1崖蜜、首先下載bootsrtap代碼(http://v3.bootcss.com/getting-started/#download),并將下載后的文件放在project下新創(chuàng)建的static目錄下萧锉。下載jquery(https://jquery.com/download/)放在static/js/目錄下俱萍。
2膀篮、下載合適的bootstrap模版樣式(http://v3.bootcss.com/getting-started/)察滑,下載的文件包含一個(gè)html和一個(gè)目錄毒坛。
實(shí)例模板:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3個(gè)meta標(biāo)簽*必須*放在最前面,任何其他內(nèi)容都*必須*跟隨其后嚷往! -->
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link rel="stylesheet">
<!-- HTML5 shim 和 Respond.js 是為了讓 IE8 支持 HTML5 元素和媒體查詢(media queries)功能 -->
<!-- 警告:通過 file:// 協(xié)議(就是直接將 html 頁(yè)面拖拽到瀏覽器中)訪問頁(yè)面時(shí) Respond.js 不起作用 -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<h1>你好葛账,世界!</h1>
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依賴 jQuery皮仁,所以必須放在前邊) -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<!-- 加載 Bootstrap 的所有 JavaScript 插件。你也可以根據(jù)需要只加載單個(gè)插件。 -->
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>