一聚教程网:一个值得你收藏的教程网站

热门教程

Mac下django简单安装配置步骤

时间:2022-11-14 22:07:55 编辑:袖梨 来源:一聚教程网


一、安装软件包并创建项目

$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',
}
}
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('

hello welcome to django!

')
3、测试

启动django


#sudo python manage.py runserver
访问:

http://localhost:8000/index

热门栏目