创建工程:
1、切换到文件夹所在目录
C:\Administrator>d:
D:\>cd d:\djangoweb
2、创建工程(成功没有提示)
d:\djangoweb>django-admin.py startproject website
d:\djangoweb>
配置setting.py文件:
DEBUG = True #是否打开调试信息
#时区
TIME_ZONE = ‘Asia/Shanghai‘
#语言类型
LANGUAGE_CODE = ‘zh-cn‘
#配置工程所包含的网站
INSTALLED_APPS = (
‘django.contrib.auth‘,
‘django.contrib.contenttypes‘,
‘django.contrib.sessions‘,
‘django.contrib.sites‘,
‘django.contrib.messages‘,
‘django.contrib.staticfiles‘,
‘blog‘,
)
配置urls.py:
urlpatterns = patterns(‘‘,
#在我们输入的URL地址包含blog/index时,就会去访问blog.views视图中的index视图函数
url(r‘^blog/index/$‘, ‘blog.views.index‘),
# Examples:
# url(r‘^$‘, ‘website.views.home‘, name=‘home‘),
)
创建app:
d:\djangoweb>cd website
d:\djangoweb\website>django-admin.py startapp blog
d:\djangoweb\website>
views.py文件 定义一个index视图函数:
# -*- coding: cp936 -*-
from django.http import HttpResponse
#定义一个index视图函数
def index(request):
return HttpResponse(‘<h1>hello world</h1>‘)
启动站点:
C:\Users\Administrator>d:#切换D盘符下
d:\djangoweb>cd website #切换D盘表的website目录
d:\djangoweb\website>manage.py runserver #启动站点
Validating models...
0 errors found
January 03, 2016 - 14:17:34
Django version 1.5.12, using settings ‘website.settings‘
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
在浏览器地址中输入:http://127.0.0.1:8000/,在添加blog/index/后缀即可查看inde结果。