![](/img/trans.png)
[英]Django - TypeError: _clone() takes exactly 1 argument (3 given)
[英]django deployment using fabric - TypeError: prepare_deployment() takes exactly 1 argument (0 given)
我正在使用此指南: 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')
但是,當我輸入此命令時(如指南中所示):
晶圓廠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文檔中的每個任務參數上閱讀有關它的信息 。
如果您確實需要在bash命令中使用方括號,則需要對其進行轉義。
如您所述,此功能應如下所示...
def prepare_deployment(branch_name):
local('python manage.py test finance')
local('git add -p && git commit')
local('git checkout master && git merge ' + branch_name)
然后您只需致電...
fab prepare_deployment("v0.1")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.