Python django部署使用fabric-TypeError:prepare_deployment()正好接受1个参数(给定0)

Python django部署使用fabric-TypeError:prepare_deployment()正好接受1个参数(给定0),python,django,fabric,Python,Django,Fabric,我正在使用此指南: 来建立我的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') loc

我正在使用此指南:

来建立我的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')
但当我输入此命令时(如指南所示):

工厂准备部署

我得到这个错误:

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)
Warning: Command(s) not found:
    v0.1

Available commands:
    deploy
    prepare_deployment
我还注意到,在函数prepare_deployment中的fabfile.py文件指南中,输入写为“branch_name”,函数内部有参数“branchname”。所以我认为应该是相同的,并将“branchname”重命名为“branchname”,但仍然得到相同的错误

所以我觉得我做错了什么。有什么问题吗

更新: 我尝试使用以下命令调用fabfile.py中的函数:

准备_部署(“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”。也许这些是相互冲突的?

如您所述,此函数应该如下所示

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")

fabric使用特定语法从命令行向任务传递参数。从bash shell中,您需要使用

fab prepare_deployment:v0.1
你可以在报纸上看到


如果您确实需要在bash命令中使用括号,则需要将其转义

这一个给了我错误:bash:syntax-error靠近意外的标记“(”但后来我尝试调用fabfile.py中的函数write:prepare\u deployment(“v0.1”)它运行了,但给了我错误:创建测试数据库时出错:创建数据库的权限被拒绝部署时是否需要一些额外的数据库连接配置?能否从命令行运行
python manage.py test finance
,没有错误?否,给出了相同的错误。我想数据库名和应用程序名是这样的不管是否相同?所有应用都会出错。因此,出于某种原因,它无法访问数据库。原因很多。听起来settings.py的内容不正确。我建议打开一个新问题并发布settings.py的数据库部分。谢谢。我会的。因为您的回答解决了此错误,所以我会接受的。