Django 简介及安装

贴两句Django官网的原话:

Meet Django-The Web Framework for perfectionists with deadlines.

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.

Developed four years ago by a fast-moving online-news operation, Django was designed to handle two challenges: the intensive deadlines of a newsroom and the stringent requirements of the experienced Web developers who wrote it. It lets you build high-performing, elegant Web applications quickly.

Django focuses on automating as much as possible and adhering to the DRY principle.(Don't Repeat Yourself.)

The Django framework

Object-relational mapper

Define your data models entirely in Python. You get a rich, dynamic database-access API for free — but you can still write SQL if needed.

Automatic admin interface

Save yourself the tedious work of creating interfaces for people to add and update content. Django does that automatically, and it's production-ready.

Elegant URL design

Design pretty, cruft-free URLs with no framework-specific limitations. Be as flexible as you like.

Template system

Use Django's powerful, extensible and designer-friendly template language to separate design, content and Python code.

Cache system

Hook into memcached or other cache frameworks for super performance — caching is as granular as you need.

Internationalization

Django has full support for multi-language applications, letting you specify translation strings and providing hooks for language-specific functionality.

更多了解参见:http://www.djangoproject.com/

Django的安装:

以下在windowsxp和ubuntu下测试通过。

当前最新发行版本是1.2.5。如果使用Django进行网站开发,不建议使用0.96及先前版本,因为1.0以后版本有较大的变化。

以1.2.5为例。 下载Django-1.2.5.tar.gz.解压。(确认首先安装了python)

1.打开命令行/终端,进入主目录.\Django-1.2.5\,然后运行:(如果是ubuntu,直接在终端运行sudo apt-get install python-django 即可,但版本肯能不是最新的,也可以按照步骤1所述进行安装,不过也要进行环境变量的设置,在此不做叙述)

python setup.py install

2. 如果不出错,即完成了安装。然后需要设置一下环境变量(windows环境).
找到python安装目录,如D:\Python26,将D:\Python26\Lib\site-packages\django\bin添加到环境变量中。这样,在命令行就可以执行django-admin.py。

在命令行键入以下代码,将会看到当前django的版本。

C:\>python
Python
2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
Type
"help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION

3. 建立工程mysite,在命令行执行:(在ubuntu下不需要写.py, 如果使用的是apt-get install 的安装方式)

django-admin.py startproject mysite

然后在当前目录就建立了一个工程mysite.

4. 进入mysite目录,执行

python manage.py runserver

然后打开web browser, 键入http://localhost:8000, 会看到It worked!等字样,恭喜你,你已经建立了你的第一个django工程。

posted @ 2011-02-22 21:07  ARVision  阅读(391)  评论(0编辑  收藏  举报