一、安装软件包并创建项目
$sudo pip install django$sudo python -c "import django;PRint django.VERSION"(1, 7, 0, 'final', 0)$sudo django-admin startproject cmdb #创建项目$sudo django-admin startapp cmdb #创建应用二、修改配置
1、修改settings.py,添加cmdb应用,以及其他设置
INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'cmdb',)DATABASES = { 'default': { 'ENGINE': 'django.db.backends.MySQL', 'NAME': 'cmdb', 'USER': 'cmdb', 'PASSWord': 'cmdb', 'HOST': 'localhost', 'PORT': '3306',(www.111cn.net) }}LANGUAGE_CODE = 'zh-cn'TIME_ZONE = 'Asia/Shanghai'2、修改urls.py和views.py
urls.py内容如下:
from django.conf.urls import patterns, include, urlfrom django.contrib import adminurlpatterns = patterns('', # Examples: # url(r'^$', 'cmdb.views.home', name='home'), # url(r'^blog/', include('blog.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^index/','cmdb.views.index'),)views.py内容如下:
from django.shortcuts import renderfrom django.http import HttpResponsedef index(req): return HttpResponse('<h1>hello welcome to django!</h1>')3、测试
启动django
#sudo python manage.py runserver访问:
http://localhost:8000/indexfrom:http://www.111cn.net/sys/linux/67502.htm
新闻热点
疑难解答