简体   繁体   English

Django Google App Engine,如何使用 Google Cloud Storage 提供 static 文件

[英]Django Google App Engine, how to serve static files using Google Cloud Storage

I have a Django app running on Google App Engine.我有一个在 Google App Engine 上运行的 Django 应用程序。

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.我希望所有对 static 内容的请求都不会由 Django 应用程序提供,而是由我已经上传了应用程序所需的所有内容的 Google Cloud Storage 存储桶提供服务。

The storage bucket has public access and I can see the static content with the browser with urls like this:存储桶具有公共访问权限,我可以通过浏览器查看 static 内容,网址如下:

https://storage.googleapis.com/my-bucket/static/image.jpg 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:基本上我需要知道的是如何配置 app.yaml 文件,以便这样的请求:

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

will be served by the storage: https://storage.googleapis.com/my-bucket/static/image.jpg将由存储提供服务: 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?使用 Ngix/Apache 这是一个标准的东西,但我怎样才能在 GCP 上实现呢? I did not find a working solution on the documentation.我没有在文档中找到可行的解决方案。 Thanks谢谢

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:您可以直接在settings.py配置文件中进行设置,方法是让您的 STATIC_URL 指向您的 Google Cloud Storage 存储桶,如下所示:

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.然后,您的 static 文件 url 将从该基本路径构建并直接从 Google Cloud Storage 提供。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用带有Django的Google App Engine安全地提供静态文件? - How to serve static files securely using google app engine with django? 从 Google Cloud Storage Bucket 提供静态文件(用于 GCE 上托管的 Django 应用) - Serve Static files from Google Cloud Storage Bucket (for Django App hosted on GCE) 如何使用 Google App Engine + Django 和 JQuery File Upload 将大文件上传到 Google Storage - How to upload large files to Google Storage using Google App Engine + Django and JQuery File Upload 如何在 django rest 框架中使用应用引擎在谷歌云存储上传图像? - how to upload image at google cloud storage using app engine in django rest framework? Google App Engine + Google Cloud Storage + Sqlite3 + Django / Python - Google App Engine + Google Cloud Storage + Sqlite3 + Django/Python 使用带有搜索过滤器的 Django 的 Google App Engine 的 Google Cloud Storage 签名 URL - Google Cloud Storage Signed URL with Google App Engine using Django with Search Filters 如何在Google Compute Engine上托管的Django应用中使用Google云端存储? - How to use Google Cloud Storage in a Django app hosted on Google Compute Engine? 带有App Engine的Django上没有名为boto Google Cloud Storage的模块 - No module named boto Google Cloud Storage on Django with App Engine 在App Engine上从Django上传到Google云端存储 - Uploading to Google Cloud Storage from Django on App Engine Google Cloud App Engine (Django) 和 Google Cloud Storage 在具有自定义 URL 的单个域上工作 - Google Cloud App Engine (Django) and Google Cloud Storage working on a Single Domain with Custom URLs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM