我正在使用本指南: http://www.jeffknupp.com/blog/2012/02/09/starting-a-django-project-the-right-way/
设置我的 django 项目。但我陷入了部署部分。 我在 virtualenv 中使用 pip 安装了 Fabric。 我在 myproject 目录中创建了这个文件:
from fabric.api import local
def prepare_deployment(branch_name):
local('python manage.py test finance')
local('git add -p && git commit')
local('git checkout master && git merge ' + branchname)
from fabric.api import lcd
def deploy():
with lcd('home/andrius/djcode/myproject/'):
local('git pull /home/andrius/djcode/dev/')
local('python manage.py migrate finance')
local('python manage.py test finance')
local('/my/command/to/restart/webserver')
但是当我输入此命令时(如指南中所示):
fab prepare_deployment
我收到此错误:
Traceback (most recent call last):
File "/home/andrius/env/local/lib/python2.7/site-packages/fabric/main.py", line 732, in main
*args, **kwargs
File "/home/andrius/env/local/lib/python2.7/site-packages/fabric/tasks.py", line 345, in execute
results['<local-only>'] = task.run(*args, **new_kwargs)
File "/home/andrius/env/local/lib/python2.7/site-packages/fabric/tasks.py", line 121, in run
return self.wrapped(*args, **kwargs)
TypeError: prepare_deployment() takes exactly 1 argument (0 given)
因此,即使指南中没有指定输入参数,我想它需要我的分支名称。所以输入这个:
fab prepare_deployment v0.1
(v0.1是我的分支名称) 所以现在我得到了这个错误:
Warning: Command(s) not found:
v0.1
Available commands:
deploy
prepare_deployment
我还注意到在函数prepare_deployment中的文件fabfile.py指南中,输入被写为“branch_name”,并且函数内部有参数“branchname”。所以我认为它应该是相同的并将“branchname”重命名为“branch_name”,但仍然遇到相同的错误。
所以我认为我在这里做错了什么。可能是什么问题?
更新: 我尝试使用以下命令调用 fabfile.py 中的函数:
prepare_deployment("v0.1")
输出是这样的:
[localhost] local: python manage.py test finance
Creating test database for alias 'default'...
Got an error creating the test database: permission denied to create database
Type 'yes' if you would like to try deleting the test database 'test_finance', or 'no' to cancel: yes
Destroying old test database 'default'...
Got an error recreating the test database: database "test_finance" does not exist
Fatal error: local() encountered an error (return code 2) while executing 'python manage.py test finance'
Aborting.
我想我还应该提到我的应用程序名称是“finance”,作为数据库名称“finance”。也许这些是冲突的?
最佳答案
fabric 使用特定语法从命令行将参数传递给任务。在 bash shell 中,您需要使用
fab prepare_deployment:v0.1
您可以在fabric documentation on per task arguments中阅读相关内容。 .
如果您确实需要在 bash 命令中使用括号,则需要转义它们。
关于python - 使用结构进行 django 部署 - TypeError : prepare_deployment() takes exactly 1 argument (0 given),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14180952/