1.准备环境 python3.7
2.安装django pip3 install django
验证是否安装成功

django-admin --version
2.2.1
3.创建项目,在workspace目录下
django-admin startproject myproject
创建成功后会在workspace下出现一个myproject文件
进入myproject目录
cd myproject
django-admin.py startapp testapp
4.配置settings.py
打开myproject/myproject/settings.py
添加testapp
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'testapp',
]
设置中文(注意有的说要设置为‘zh-cn’,但Lib\site-packages\django\conf\locale目录下没有zh-cn这个文件,所以我们用zh-Hans)
#语言
LANGUAGE_CODE = 'zh-Hans'
#时区
TIME_ZONE = 'Asia/Shanghai'
5.测试django服务
在myproject下,执行
python managy.py runserver 0.0.0.0:8000
...
Django version 2.2.1, using settings 'myproject.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CTRL-BREAK.
在浏览器输入http://localhost:8000访问成功,即基本服务搭建完成
6.bootstrap 网站模板,及django配置
在workspace/myproject下创建static 文件夹
并从github上下载bootstrap下载地址为
https://github.com/twbs/bootstrap/releases/download/v3.3.1/bootstrap-3.3.1-dist.zip
然后将下载的css,js,fonts文件拷贝到static文件夹下
7.配置静态文件
STATIC_URL = '/static/'
STATICFILES_DIRS = (
BASE_DIR+'/static/',
)
8.在workspace/myproject/testapp/下创建templates文件夹并在下面新建index.html




    
    
    
    
    ;

    Starter Template for Bootstrap
    
    
 
    ;
    
    

  

    


表格


.table 为任意表格添加基本样式 (只有横向分隔线):























#Firstname
1Anna
2Debbie
3John



9.打开workspace/myproject/testapp/views.py,
def index(request):
return render(request,index.html')
10.打开workspace/myproject/myproject/urls.py配置访问路径
from django.contrib import admin
from django.urls import path
from testapp import views

urlpatterns = [
path('admin/', admin.site.urls),
path(index/', views.index),
]
11.启动项目访问http://localhost:8000/index即可