django入门(一)安装和HelloWorld

django入门(一)安装和HelloWorld

阅读别人的中文笔记
http://www.woodpecker.org.cn/obp/django/django-stepbystep/newtest/doc/

同时查看了官方网站,前段时间玩的python都是3.1版本,原来django只支持到2.x版本,所以我卸载了python3.1,重新安装了python2.6.4版本。

step by step(一)
3.1
安装完成python后,将C:\Python26加入到path中,以便在命令行中使用。
下载django
http://www.djangoproject.com/download/
得到文件
Django-1.1.1.tar.gz
用winzip解开压缩,拷贝到c盘,呵呵,拷贝过去是方便以后查阅
cd Django-1.1.1
输入安装命令
setup.py install
安装完成后,将目录C:\Python26\Scripts也加入到path中,方便以后调用django-admin.py

3.2 生成项目
cd d:/work
生成项目文件夹
django-admin.py startproject easydjango
于是在文件夹中,生成了4个文件
__init__.py 表示这是一个python包,里面没有内容
manage.py 提供简单化的django-admin.py命令
settings.py 配置文件
urls.py       url映射文件

3.3 启动服务
manage.py runserver
控制台返回信息如下:
Validating models...
0 errors found

Django version 1.1.1, using settings 'easydjango.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

访问http://localhost:8000

已经安装启动成功。

3.4 增加helloworld应用
我在eclipse中新建了easydjango项目,并将django目录和eclipse生成的easydjango目录合并。
新建包com.sillycat.easydjango,并新建文件HelloWorld.py如下:
from django.http import HttpResponse
def index(request):
    return HttpResponse("Hello, World.")

3.5 修改urls.py文件
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
    # Example:
    # (r'^easydjango/', include('easydjango.foo.urls')),
    (r'^$', 'easydjango.src.com.sillycat.easydjango.HelloWorld.index'),

    # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
    # to INSTALLED_APPS to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    # (r'^admin/', include(admin.site.urls)),
)

以上r'^$'是匹配空串,访问http://localhost:8000就能访问到hell,world了。

你可能感兴趣的:(eclipse,C++,c,django,python)