Domanda

I'd like to do something like this:

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

Is there an easy way to achieve this?

È stato utile?

Soluzione

You could use Fabric to collect and deploy the static files to a remote server.

There's sample code in the Django documentation.

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
    )

You would then deploy the static files by running:

fab deploy_static
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top