add setting to force remote serving of media even when DEBUG = True

This commit is contained in:
Jeremy Carbaugh
2009-07-30 23:09:54 -04:00
parent 9af05810de
commit c545d7877a
2 changed files with 10 additions and 5 deletions
+6 -2
View File
@@ -52,7 +52,7 @@ Add to INSTALLED_APPS:
Additionally, replace the existing __MEDIA\_URL__ setting with:
MEDIA_URL = '/media/'
__MEDIA\_URL__ is the URL that will be used in debug mode. Otherwise, the __MEDIA\_URL__ will be inferred from the settings listed below.
The following settings must also be added:
@@ -82,6 +82,10 @@ Previous versions of mediasync rewrote URLs in CSS files to use the correct __ME
MEDIASYNC_REWRITE_CSS = True
The media URL is selected based on the __DEBUG__ attribute in settings.py. When *True*, media will be served locally instead of from S3. Sometimes it is necessary to serve media from S3 even when __DEBUG__ is *True*. To force remote serving of media, set __MEDIASYNC\_SERVE\_REMOTE__ to *True*.
MEDIASYNC_SERVE_REMOTE = True
### urls.py
A static media URL needs to be setup in urls.py that enables access to the media directory ONLY IN DEBUG MODE.
@@ -169,4 +173,4 @@ When pushed to S3, the local URL is rewritten as the MEDIA\_URL from settings.py
## Running MEDIASYNC
./manage.py mediasync
./manage.py syncmedia
+4 -3
View File
@@ -10,15 +10,16 @@ register = template.Library()
assert hasattr(settings, "MEDIASYNC_AWS_BUCKET")
SERVE_REMOTE = getattr(settings, "MEDIASYNC_SERVE_REMOTE", not settings.DEBUG)
BUCKET_CNAME = getattr(settings, "MEDIASYNC_BUCKET_CNAME", False)
AWS_PREFIX = getattr(settings, "MEDIASYNC_AWS_PREFIX", None)
if settings.DEBUG:
mu = settings.MEDIA_URL
else:
if SERVE_REMOTE:
mu = (BUCKET_CNAME and "http://%s" or "http://%s.s3.amazonaws.com") % settings.MEDIASYNC_AWS_BUCKET
if AWS_PREFIX:
mu = "%s/%s" % (mu, AWS_PREFIX)
else:
mu = settings.MEDIA_URL
MEDIA_URL = mu.rstrip('/')