2014-06-05 290 views
0

我正在嘗試配置我的django安裝程序以在調試和生產模式下提供靜態文件。我希望生產模式是從S3,並在調試模式下從本地安裝。我的設置如下:Django提供靜態文件

COMPRESS_ENABLED = not DEBUG 
COMPRESS_PARSER = 'compressor.parser.LxmlParser' 
COMPRESS_CSS_FILTERS = ['compressor.filters.cssmin.CSSMinFilter'] 
COMPRESS_JS_FILTERS = ['compressor.filters.jsmin.JSMinFilter'] 
COMPRESS_STORAGE = 'storages.backends.s3boto.S3BotoStorage' 
DEFAULT_FILE_STORAGE = 'libs.storages.S3Storage.S3Storage' 

AWS_ACCESS_KEY_ID = # Key 
AWS_SECRET_ACCESS_KEY = # Secret 

AWS_STORAGE_BUCKET_NAME = # Bucket 

AWS_QUERYSTRING_AUTH = False 

MEDIA_URL = '/media/' 
if COMPRESS_ENABLED: 
    from boto.s3.connection import SubdomainCallingFormat 
    AWS_S3_CALLING_FORMAT = SubdomainCallingFormat() 

    COMPRESS_OFFLINE = True 
    STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage' 

    # Path for all static files 
    STATIC_URL = 'https://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME 
    STATIC_ROOT = STATIC_URL 
else: 
    STATIC_ROOT = path.join(PROJECT_ROOT, '..', 'assets') 
    STATIC_URL = '/static/' 

我能夠讓所有的東西都能工作,除了一件我無法弄清楚的小東西。通常情況下,我的CSS文件將有一個後臺網址爲/images/logo.png。 S3中存在文件夾/images/,但對於我的本地文件夾,它需要爲/static/images/。我試圖在最後設置S3 URL爲/static/,但它不起作用。還有什麼我失蹤?如何獲取CSS圖像網址重定向到/static/

回答

0

我通過s3boto.py的源代碼閱讀。您可以設置以下屬性:

AWS_LOCATION = "static" 

該變量會在您的S3一個static文件夾。其他性質應該是:

STATIC_URL = 'https://%s.s3.amazonaws.com/static/' % AWS_STORAGE_BUCKET_NAME 
STATIC_ROOT = STATIC_URL