安装Django
pip3 install django
MTV模式
model 数据库相关
template html
v view 逻辑处理
manage.py 操作项目命令
settings 配置文件
url 控制器
wsgi 封装socket
python manage.py startapp app01
app01--
admin 数据库后台管理工具
apps
models(重点)
tests
views(重点)
代码部分 最简单流程 访问请求到urls文件 urls文件调用views.py文件
启动: Terminal控制台
python manage.py runserver 8080
url文件
"""Dajon_demo URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from app01 import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^index/', views.index),
]
views文件
from django.shortcuts import render,HttpResponse
# Create your views here.
import datetime
def index(request):
timer=datetime.datetime.now()
return HttpResponse(timer)