django 基础入门(一)
1. django 基本命令
新建project
django-admin.py startproject project-name
新建app
python manage.py startapp app-name
数据库操作
python3.5 manage.py makemigrations
python3.5 manage.py migrate
python3.5 manage.py flush
2、目录结构
project目录
mysite
├── manage.py
└── mysite
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
app目录
cmdb/
|___ migrations
├── __init__.py
├── admin.py
|____ apps.py
├── models.py
├── tests.py
└── views.py
修改settings文件
INSTALLED_APPS
=
(
'django.contrib.admin'
,
'django.contrib.auth'
,
'django.contrib.contenttypes'
,
'django.contrib.sessions'
,
'django.contrib.messages'
,
'django.contrib.staticfiles'
,
'cmdb'
,
)
修改urls
from django.conf.urls import url,include from django.contrib import admin from IDC import views urlpatterns = [ # url(r'^$', IDC.urls.index), url(r'^cmdb/', include("IDC.urls")), url(r'^moniter/', include("moniter.urls")), ]
from django.conf.urls import url from django.contrib import admin from IDC import views urlpatterns = [ # url(r'^home/', views.home), url(r'^$', views.login), url(r'^check/', views.check), url(r'^db_handle/', views.db_handle), url(r'^del/', views.db_del), ]
def home(request): # return "asdf" return HttpResponse('moniter.home')