3
votes

I have a Django app running on Google App Engine.

I want that all the requests for static content will be served not by the Django app but a Google Cloud Storage bucket on which I've already uploaded all the content that the app needs.

The storage bucket has public access and I can see the static content with the browser with urls like this:

https://storage.googleapis.com/my-bucket/static/image.jpg

Basically what I need to know is how to configure the app.yaml file so that requests like these:

https://www.mydjangoapp.com/static/image.jpg

will be served by the storage: https://storage.googleapis.com/my-bucket/static/image.jpg

With Ngix/Apache this is a standard thing, but how can I achieve this on GCP? I did not find a working solution on the documentation. Thanks

1
you can write a webapp handler, which get data from gcs and then serve itPraveen Soni
Thanks but this is a thing I want to avoid, the app itself must not spend computing resources in serving static content, it's a best practicejohncarlof
yaa, but as per my understanding without it, you can't reroute, even with dispatch.yamlPraveen Soni
In this case Google App Engine would have severe limitations serving static content separately is a standard feature, I can not believe GAE lacks of thisjohncarlof

1 Answers

1
votes

You can set this up directly in your settings.py configuration file by making your STATIC_URL point to your Google Cloud Storage bucket, like so:

STATIC_URL = 'https://storage.googleapis.com/my-bucket/static/'

Your static files urls will then be constructed from this base path and served directly from Google Cloud Storage.