Python Web notes (ii)
=================================================================================================
Third, Django Create app
=================================================================================================
1. First use Django-admin to create the good one Django project
Django-admin Startproject test01
2. Execute commands under the test01 directory
D:\python2.7.13\exercise\test01>python manage.py Startapp CMDB #app名称为cmdb
D:\python2.7.13\exercise\test01>python manage.py Startapp OpenStack
3, check the directory (use Pycharm open view), confirm whether the creation is successful!
650) this.width=650; "Width=" 501 "height=" 169 "title=" 123.png "style=" width:374px;height:120px; "alt=" wKioL1nXbZ_ Ybjioaaaf0rbncug114.png-wh_50 "src=" Https://s5.51cto.com/wyfs02/M02/A6/A9/wKioL1nXbZ_ybJioAAAf0RbNCUg114.png-wh _500x0-wm_3-wmp_4-s_491767165.png "/>
4. Accessing the project CMDB in the browser
1) The directories in the newly created CMDB app are:
650) this.width=650; "Width=" 502 "height=" 318 "title=" 456.png "style=" width:380px;height:228px; "alt=" Wkiom1nxcadxdipsaaaqpz46hzc176.png-wh_50 "src=" https://s1.51cto.com/wyfs02/M01/07/F7/ Wkiom1nxcadxdipsaaaqpz46hzc176.png-wh_500x0-wm_3-wmp_4-s_3099032975.png "/>
2) Modify the views.py file in the CMDB with the following configuration:
From django.shortcuts import renderfrom django.shortcuts import httpresponse #加入 # Create your views Here.def home (Request ): #定义函数home return HttpResponse (' 3) Modify the urls.py file in the project
from django.conf.urls import urlfrom django.contrib import adminfrom django.shortcuts import httpresponse #导入HttpServer模块import time #加入from cmdb import views #导入cmdb app in Viewsdef home (request): # Define a function Home return httpresponse (' 4) Open the Django server:
5) Browser Access test:
650) this.width=650; "Width=" "height=" "title=" 789.png "style=" width:397px;height:91px "alt=" Wkiom1nxcyidy1cqaaa0hnd2_by150.png-wh_50 "src=" https://s4.51cto.com/wyfs02/M02/07/F7/wKiom1nXcyiDY1CqAAA0HNd2_ By150.png-wh_500x0-wm_3-wmp_4-s_4279450203.png "/>
This article from "Doublelinux" blog, declined reprint!
Python Web notes (ii)