search

Home  >  Q&A  >  body text

How to use Fabric in Django project?

I want to synchronize files to a remote server in Django. I saw that the rsync_project method under Fabric's fabric.contrib.project can synchronize files.

#!/usr/bin/env python3

from fabric.contrib.project import rsync_project
from fabric.api import env, execute

env.hosts = ['172.30.200.82', '172.30.200.87']

def test():
    rsync_project(local_dir='/data/logstash-2.2.2', remote_dir='/data')

if __name__ == '__main__':
    test()

As above, directly executing python test.py will prompt No hosts found. Please specify (single) host string for connection:, be sure to use the command line to execute fab -f test.py test can run correctly. Now I want to put this function into the Django background. I also encountered this problem. I would like to ask how to integrate this function into Django, that is, let this function run directly. It can be executed without the need to go to the command line and use the fab command to call it again.

黄舟黄舟2743 days ago771

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-27 17:41:51

    Use subprocess module?

    reply
    0
  • Cancelreply