文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>1.Install and say

1.Install and say

时间:2010-05-30  来源:CZFanny

1.Software download

1) http://www.python.org/download/releases/2.5.4/
下载python-2.5.4.msi
2) http://www.djangoproject.com/download/
下载Django-1.0.2-final.tar.gz
3) http://sourceforge.net/projects/mysql-python/
下载MySQL-python-1.2.2.win32-py2.5.exe

2. Software Installation:
1) Install Python: python-2.5.1.msi [higher version like PortablePython_1.1_py3.0.1.rar may has error when install Django(1.1.1,1.2.1)]
2) Install Django: Django-1.1.1.tar
将Django-1.1.1.tar解压到python的安装目录下(本例为C:\Python25\Django-1.1.1),命令行进入C: \Python25,执行“python Django-1.1.1/setup.py install” ,Django即被安装到C:\Python25\Lib\site-packages\django下(C:\Python25\Django-1.1.1可删除)。
# 执行python提示找不到该命令时,说明没有设置环境变量。
  [右击“我的电脑”->“属性”->“高级”->“环境变量”,选择“PATH”,点“编辑”,把;C:\Python25加入“变量值”中(注意分号分割)。确定。针对   python的环境变量重启cmd就可以了,但是设置关于系统服务的环境变量就必须重启电脑了.]
3) Install MySQL-python: MySQL-python-1.2

3. Test environment is ready:
1) C:\Python25>python C:\Python25\Lib\site-packages\django\bin\django-admin.py startproject mysite
  在当前目录(运行命令的目录)创建一个 mysite 目录。
       mysite/
          __init__.py  [让 Python 把该目录当成一个开发包 (即一组模块)所需的文件。]
          manage.py    [一种命令行工具,可让你以多种方式与该 Django 项目进行交互。]
          settings.py  [该 Django 项目的设置或配置。]
          urls.py      [该 Django 项目的 URL 声明,即 Django 所支撑站点的内容列表。]
2) python manage.py runserver
   # 默认情况下, runserver  命令在 8000 端口启动开发服务器,且只监听本机连接。要想要更改服务器端口的话,可将端口作为命令行参数传入:
3) 服务器已经运行起来了,现在用网页浏览器访问 http://127.0.0.1:8000/ 。你应该可以看到一个欢快的淡蓝色所笼罩的 Django 欢迎页面。一切正常!

4.A small example:
1) Base on phase 3.

2) Make a new file named:view.py

from django.http import HttpResponse
import datetime

def current_datetime(request):
    now = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    return HttpResponse(html)


3) Edit urls.py:

from django.conf.urls.defaults import *
from mysite.view import current_datetime

# 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/', include(admin.site.urls)),
    (r'time/$',current_datetime),
)


4) Input:http://127.0.0.1:8000/time/ into browser

5. Go further
1) Base on phase 4.

2) Edit view.py,add following function:

def hours_ahead(request,offset):
    offset = int(offset)
    dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
    html = "<html><body>In %s hour(s), it will be %s.</body></html>" % (offset,dt)
    return HttpResponse(html)


3) Edit urls.py:

from django.conf.urls.defaults import *
from mysite.view import current_datetime,hours_ahead

urlpatterns = patterns('',
    (r'time/$',current_datetime),
    (r'time/plus/(\d{1,2})/$',hours_ahead)
)


4) Input into browser:
   http://127.0.0.1:8000/time/
   http://127.0.0.1:8000/time/plus/3/
   http://127.0.0.1:8000/time/plus/31/
相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载