django-admin.py startproject mysite
建立後的項目結構: - mysite - mysite #對整個程序進行配置 - init #導入包專用 - settings #配置文件 - url #url對應關係 - wsgi #遵循WSGI規範,uwsgi+nginx - manage.py #管理Django程序 - templates #網頁模板
python manage.py startapp myapp
mysite #APP名字 migrations #數據修改表結構 admin #Django爲咱們提供的後臺管理功能 models #ORM,寫指定的類,經過命令建立數據庫結構 tests #單元測試 views #業務代碼
python manage.py runserver 8080
python manage.py makemigrations python manage.py migrate
python manage.py flush
此命令會詢問是 yes 仍是 no, 選擇 yes 會把數據所有清空掉,只留下空表。python
python manage.py createsuperuser
python manage.py changepassword username
python manage.py shell python manage.py dbshell
1.建立項目和appnginx
2.啓動訪問shell
3.urls.py數據庫
from django.conf.urls import url from django.contrib import admin from myapp import views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^home', views.home), ]
4.views.pydjango
from django.shortcuts import render,HttpResponse,redirect def home(request): return HttpResponse('<h1>CMDB</h1>')
5.models.py瀏覽器
from django.db import models class UserType(models.Model): name = models.CharField(max_length=32) class UserInfo(models.Model): username = models.CharField(max_length=32) pwd = models.CharField(max_length=32) email = models.CharField(max_length=32)
5.創建數據庫app
執行下面三行命令: python manage.py makemigrations python manage.py migrate python manage.py createsuperuser # 創建用戶
6.admin.py單元測試
from django.contrib import admin from myapp import models admin.site.register(models.UserInfo) admin.site.register(models.UserType)
7.經過瀏覽器訪問測試