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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。