1

我想做这样的事情:

STATIC_ROOT = 'user@123.123.123.132:/home/static-files/'

有没有简单的方法来实现这一目标?

4

1 回答 1

4

您可以使用Fabric收集静态文件并将其部署到远程服务器。

Django 文档中有示例代码。

from fabric.api import *
from fabric.contrib import project

env.roledefs['static'] = ['user@123.123.123.132',]    

# Where the static files get collected locally. Your STATIC_ROOT setting.
env.local_static_root = '/tmp/static'

# Where the static files should go remotely
env.remote_static_root = '/home/static-files'

@roles('static')
def deploy_static():
    local('./manage.py collectstatic')
    project.rsync_project(
        remote_dir = env.remote_static_root,
        local_dir = env.local_static_root,
        delete = True
    )

然后,您将通过运行以下命令部署静态文件:

fab deploy_static
于 2013-09-27T14:55:01.857 回答