Bootstrap

Django ORM映射

第一步 创建项目

到cmd输入 python manage.py startproject (项目名)
再到python里配置环境

第二步 创建 app01

python manage.py startapp app01

第三步 自建 app01

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'app01.apps.App01Config'
]

第四步 配下项目路由

from django.contrib import admin
from django.urls import path,include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('app01',include('app01.urls'))
]

第五步 配子路由

from django.urls import path,include
from . import views

urlpatterns = [
    path('index',views.index)
]

第六步 到views中写 函数视图

from django.shortcuts import render

# Create your views here.

def index(request):
    context = {
   'list':[{
   'id':'1','name':'张三','age':31},{
   'id':'2','name':'李四','age':29}]}
    return render(request,'index.html',context=context)

第七步 创建templates项目中的html页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
;