简体   繁体   English

使用zc.buildout在'$ django-admin.py startproject my_project'之后自动定制Django项目

[英]Automating customisation of Django projects after '$ django-admin.py startproject my_project' with zc.buildout

I have skimmed the official zc.buildout documentation and some tuts but I haven't found a clear answer to the following question. 我已经浏览了官方zc.buildout文档和一些内容,但我没有找到以下问题的明确答案。

Suppose I wanted to automate the following changes in every Django project(Django1.4) from now on, can all of those changes get executed by merely by a buildout.cfg file? 假设我想从现在开始在每个Django项目(Django1.4)中自动执行以下更改 ,是否所有这些更改都可以仅通过buildout.cfg文件执行?

After doing $ django-admin.py startproject my_project , example of changes of the default startproject I would implement: 在执行$ django-admin.py startproject my_project ,我将实现默认startproject的更改示例:

$ mkdir ~/path/to/my_project/my_project/db

settings.py: settings.py:

import os
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(ROOT_PATH, 'db/my_project.db'),                      
        'USER': '',                     
        'PASSWORD': '',                  
        'HOST': '',                    
        'PORT': '', 
    }
}

I currently build and use my own customized distribution of the 1.4 branch of the Django source as a solution but it would be nice to know if I could do it using buildout as well. 我目前正在构建和使用我自己定制的Django源1.4分支的分发作为解决方案但是很高兴知道我是否也可以使用buildout来完成它。

What you want is not really part of the Buildout set of use-cases. 你想要的并不是Buildout用例集的一部分。

You want to customize generated code when you start a project, while buildout aims at giving you a reproducible deployment or development environment. 您希望在启动项目时自定义生成的代码,而buildout旨在为您提供可重现的部署或开发环境。

The former one developer would use, the latter is aimed at getting multiple developers or multiple production machines up and running with the same software stack. 一个开发人员将使用,后者旨在使多个开发人员或多个生产计算机启动并运行相同的软件堆栈。

That said, certainly a buildout recipe can be constructed that writes out new versions of those files when the part is run. 也就是说,当然可以构建一个buildout配方,在部件运行时写出这些文件的新版本。 For example, using collective.recipe.template you could specify a template file to be placed in a certain location every time buildout is run. 例如,使用collective.recipe.template您可以指定每次运行buildout时放置在特定位置的模板文件。 Note that that would overwrite those files if they ever changed. 请注意,如果这些文件发生更改,则会覆盖这些文件。

In addition to Martijn's answer: buildout can create directories just fine. 除了Martijn的回答:buildout可以创建目录就好了。 Have a look at http://pypi.python.org/pypi/z3c.recipe.mkdir/ 看看http://pypi.python.org/pypi/z3c.recipe.mkdir/

That's one of the tasks I regularly use it for (creating a var/log/ for logfiles, a var/sqlite/ dir for the sqlite file, etc.) 这是我经常使用它的任务之一(为日志文件创建var / log /,为sqlite文件创建var / sqlite / dir等)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果已经有django项目,如何使用startproject(django-admin.py)? - How to use startproject (django-admin.py) if there is already a django project? django-admin.py startproject 库存。 不管用? - django-admin.py startproject Inventory . is not working? django-admin.py startproject 不工作 - django-admin.py startproject is not working 如何将“ python…PATH…django-admin.py startproject myprojname”减少为“ django-admin.py startproject myprojname”? - How to reduce “python …PATH…django-admin.py startproject myprojname” to “django-admin.py startproject myprojname”? 为什么“ django-admin.py startproject myproject”没有创建项目而是在Eclipse中打开django-admin.py? - Why “django-admin.py startproject myproject” doesn't create a project but instead open django-admin.py in Eclipse? django命令“ django-admin.py startproject mysite” - django command “django-admin.py startproject mysite” “ django-admin.py startproject Concept”在virtualenv中不起作用 - “django-admin.py startproject Concept” doesn't work in virtualenv django-admin.py startproject mysite 不工作 - django-admin.py startproject mysite isn't working django-admin.py startproject返回无法导入设置'settings' - django-admin.py startproject returns Could not import settings 'settings' django-admin.py startproject mysite不起作用 - Doesn't work django-admin.py startproject mysite
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM