Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python fabric无法在Django环境中使用_Python_Django_Linux_Virtualenv_Fabric - Fatal编程技术网

Python fabric无法在Django环境中使用

Python fabric无法在Django环境中使用,python,django,linux,virtualenv,fabric,Python,Django,Linux,Virtualenv,Fabric,我在本地系统中有一个fabric文件,我正在使用它在远程服务器(virtualenv)中部署代码,并希望对其进行测试。方法定义如下所示 def test_deploy(gitid = '930bfc4'): # manually put the commit id at the end path = '/tmp/testapp/app1/source/demo4' with cd(path): commit_id =

我在本地系统中有一个fabric文件,我正在使用它在远程服务器(virtualenv)中部署代码,并希望对其进行测试。方法定义如下所示

    def test_deploy(gitid = '930bfc4'):
        # manually put the commit id at the end
        path = '/tmp/testapp/app1/source/demo4'
        with cd(path):
            commit_id = 'git fetch https://myaccount@github.org/myaccount/demo4.git/heads/master:https://myaccount@github.org/myaccount/demo4.git/remotes/origin/master/'+gitid
            # change the settings.py file and update the database
            run (commit_id)
            run ('cat .git/FETCH_HEAD')

        path1 = '/tmp/testvehic/vehic'
        with cd(path1):
            run ('pwd')
            env.activate = 'source /tmp/testapp/app1/bin/activate'
            run ('python /tmp/testapp/app1/source/demo4/manage.py test')`
这表明

ImportError:没有名为django.core.management的模块

在谷歌搜索了一段时间后,我才知道它实际上并没有找到我的django环境。
我的虚拟环境路径是
/tmp/testapp/app1

源代码位于
/tmp/testapp/app1/source/app1/


当我在服务器终端中运行命令
python manage.py test
时,它工作正常。如何通过fabric进行测试?

我从下面的链接中得到了答案

我的代码片段现在如下所示

VENV_DIR = '/home/rootuser/testvehic/vehic'
PROJECT_DIR = '/home/rootuser/testvehic/vehic/source/cabsdemo4'

@contextmanager
def source_virtualenv():
    with prefix('source ' + os.path.join(VENV_DIR, 'bin/activate')):
        yield
def test_deploy(gitid = '930bfc4'):
    # manually put the commit id at the end
    path = '/tmp/testapp/app1/source/demo4'
    with cd(path):
        commit_id = 'git fetch https://myaccount@github.org/myaccount/demo4.git/heads/master:https://myaccount@github.org/myaccount/demo4.git/remotes/origin/master/'+gitid
        # change the settings.py file and update the database
        run (commit_id)
        run ('cat .git/FETCH_HEAD')
    with settings(warn_only=True):
        with cd(PROJECT_DIR):
            with source_virtualenv():
                run('pip install -r requirements.txt')
                run('python manage.py test')

停止捆绑激活东西,太多人弄错了,改为这样做:
/tmp/testvehic/vehic/bin/python/tmp/testapp/app1/source/demo4/manage.py test
保证不会失败;没有人会看代码并被它弄糊涂;易于调试;只有胜利!!:P