原文链接:http://jacobian.org/writing/django-apps-with-buildout/
注:本文仅包含具体的部署步骤,不含参数解释等。如需要可查看原文。
1.创建buildout的环境
1)运行代码:
$ mkdir -p django-shorturls/src/shorturls
$ cd django-shorturls
$ cp ~/Shrapnel/BSD_LICENSE LICENSE
$ touch README
$ wget http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py
$ cat - > buildout.cfg
[buildout]
parts =
^D
$ touch setup.py
$ touch src/shorturls/__init__.py
2)命令所产生的文件目录结构:
django-shorturls/
LICENSE
README
bootstrap.py
buildout.cfg
setup.py
src/
shorturls/
__init__.py
3)运行命令
$ python bootstrap.py
Creating directory '.../django-shorturls/bin'.
Creating directory '.../django-shorturls/parts'.
Creating directory '.../django-shorturls/eggs'.
Creating directory '.../django-shorturls/develop-eggs'.
Generated script '.../django-shorturls/bin/buildout'.
$ ./bin/buildout
Getting distribution for 'zc.buildout'.
Got zc.buildout 1.2.1.
Upgraded:
zc.buildout version 1.2.1;
restarting.
Generated script '.../django-shorturls/bin/buildout'.
4)现在我们得到了最新的目录结构
django-shorturls/
bin/
buildout
bootstrap.py
buildout.cfg
develop-eggs/
eggs/
setuptools-0.6c9-py2.5.egg/
zc.buildout-1.1.1-py2.5.egg/
zc.buildout-1.2.1-py2.5.egg/
parts/
src/
shorturls/
2.配置setup.py文件
1)内容如下:
from setuptools import setup, find_packages
setup(
name = "django-shorturls",
version = "1.0",
url = 'http://github.com/jacobian/django-shorturls',
license = 'BSD',
description = "A short URL handler for Django apps.",
author = 'Jacob Kaplan-Moss',
packages = find_packages('src'),
package_dir = {'': 'src'},
install_requires = ['setuptools'],
)
3.配置buildout
1)修改buildout.cfg文件
[buildout]
parts = python
develop = .
eggs = django-shorturls
[python]
recipe = zc.recipe.egg
interpreter = python
eggs = ${buildout:eggs}
2)再次运行./bin/buildout
$ ./bin/buildout
Develop: '.../django-shorturls/.'
Getting distribution for 'zc.recipe.egg'.
Got zc.recipe.egg 1.2.2.
Installing python.
Generated interpreter '.../django-shorturls/bin/python'.
4.使用djangorecipe这个recipe(就是别人提供的一个egg包)
1)修改buildout.cfg文件,添加:
parts = python django
...
[django]
recipe = djangorecipe
version = 1.0.2
project = shorturls
projectegg = shorturls
settings = settings
eggs = ${buildout:eggs}
2)再次运行./bin/buildout,将会在bin目录下生成django文件
3)django就和manage.py的功能相同,使用它启动django项目即可。