免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4138 | 回复: 0
打印 上一主题 下一主题

搭建Python WEB服务器三步曲 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-01 13:34 |只看该作者 |倒序浏览
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.页面呈现:



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/20294/showart_1766559.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP