Django Settings for Rendering static images from Google Cloud storage
<p>I have my Django App hosted on Google Compute Engine. I wish to render static elements of the App from Google Cloud Storage. I have all the static elements inside Google Cloud storage bucket www.example.com/static</p>

<p>My Settings.py:</p>

<pre><code># Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, '../example_static')

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, '../example_media')
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'), MEDIA_ROOT,)
</code></pre>

<p>000-default.conf File:</p>

<pre><code>&lt;VirtualHost *:80&gt;
    .....
    DocumentRoot /var/www/html

    Alias /static /opt/projects/example-google/example_static
    ....
&lt;/VirtualHost&gt;
</code></pre>

<p>With Current settings, it is picking up the static files from path: /opt/projects/example-google/example_static.</p>

<p>Can someone please explain the settings change required for rendering all the static images from Google Cloud storage bucket www.example.com/static ?</p>

<p>Thanks,</p>

<p>You can find some documentation 
    
    <a href="https://cloud.google.com/python/django/flexible-environment#deploy_the_app_to_the_app_engine_flexible_environment" rel="nofollow" >here</a>
    </p>

<p>One more thing i found useful is automatically switching between dev and prod environments by doing to following changes in your app settings.py:</p>

<pre><code>if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
    STATIC_URL = 'https://storage.googleapis.com/&lt;your-bucket&gt;/static/'
else:
    STATIC_URL = '/static/'
</code></pre>

python django google-cloud-storage google-compute-engine django-staticfiles