1. 安装django

Django的下载地址:https://www.djangoproject.com/download/

解压缩后进入这个目录,执行python setup.py install


2. 测试

#python

#import python

没有出现错误,证明安装成功


3.创建django项目

#django-admin.py startproject  web_01

4. 修改settings.py

修改TIME_ZON为  Asia/Shanghai 

修改LANGUAGE_CODE为 zh-cn

INSTALLED_APPS下添加  'blog',

INSTALLED_APPS = (

    'django.contrib.auth',

    'django.contrib.contenttypes',

    'django.contrib.sessions',

    'django.contrib.sites',

    'django.contrib.messages',

    'django.contrib.staticfiles',

     'blog',

)


5.修改urls.py 

urlpatterns 添加url(r'^blog/index/$','blog.views.index'),


from django.conf.urls.defaults import patterns, include, url

urlpatterns = patterns('',

     url(r'^blog/index/$','blog.views.index'),

)


6. 创建应用

#django-admin.py  startapp blog   

注意:blog为settings.py中INSTALLED_APPS里面添加的项目,必须一致


7. 在views.py定义index方法


from django.http import HttpResponse


def index(req):

 return HttpResponse("

welcome to django python

")


8. 开启django自带的开发服务器

#python manage.py runserver


9. 测试

http://localhost:8000/blog/index/