搭建Python WEB服务器三步曲

1.下载并安装Django
http://www.djangoproject.com/download/
目前最新版本是:Django-1.0.2-final.tar.gz
lvdbing@lvdbing-desktop:~/Application$tar xzvf Django-1.0.2-final.tar.gz
lvdbing@lvdbing-desktop:~/Application$cd Django-1.0.2-final
lvdbing@lvdbing-desktop:~/Application/Django-1.0.2-final$sudo python setup.py install
2.使用Django管理工具创建自己的站点
lvdbing@lvdbing-desktop:~$ which django-admin.py
/usr/bin/django-admin.py
安装完django后,会将django-admin.py管理工具的路径加入到/usr/bin里面去的
lvdbing@lvdbing-desktop:~$ django-admin.py startproject MySite
lvdbing@lvdbing-desktop:~$ ls
Application  Desktop  Download  Homepage  MySite  Testing  Working
lvdbing@lvdbing-desktop:~$ cd MySite/
lvdbing@lvdbing-desktop:~/MySite$ ls
__init__.py  manage.py  settings.py  urls.py
3.修改配置,启动服务
修改前:
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'^MySite/', include('MySite.foo.urls')),
    # 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/(.*)', admin.site.root),
)
修改后:
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'^MySite/', include('MySite.foo.urls')),
    # 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/(.*)', admin.site.root),
        (r'^$', 'MySite.index.index'),
)
创建第一个应用程序,index.py:
#!/usr/bin/env python
# -*- coding=utf-8 -*-
from django.http import HttpResponse
def index(request):
        return HttpResponse("欢迎使用Python架站.")
启动服务:lvdbing@lvdbing-desktop:~/MySite$ python manage.py runserverValidating models...0 errors foundDjango version 1.0.2 final, using settings 'MySite.settings'Development server is running at http://127.0.0.1:8000/Quit the server with CONTROL-C.页面呈现: