首页 > 代码库 > Mac下django简单安装配置步骤
Mac下django简单安装配置步骤
一、安装软件包并创建项目
$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, url
from django.contrib import admin
urlpatterns = 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 render
from django.http import HttpResponse
def index(req):
return HttpResponse(‘<h1>hello welcome to django!</h1>‘)
3、测试
启动django
#sudo python manage.py runserver
访问:
http://localhost:8000/index
from:http://www.111cn.net/sys/linux/67502.htm
Mac下django简单安装配置步骤