简体   繁体   English

Django 如何在 Amazon S3 中存储 HTML 文件

[英]Django How to Store HTML files in Amazon S3

I have a question regarding HTML files and Django.我有一个关于 HTML 文件和 Django 的问题。 Can the django views file serve html files that are not stored locally and stored on amazon s3? django 视图文件可以提供未存储在本地并存储在 amazon s3 上的 html 文件吗?

For example instead of:例如,而不是:

def index(request):

    return render(request, 'index.html')

have something like:有类似的东西:

def index(request):

    return render(request, 'http://bucket.s3.amazonaws.com/file.html')

Obviously its currently appending the url link to the folder it things html are served from.显然,它当前将 url 链接附加到提供 html 的文件夹。

Is this sort of thing even possible?这种事情甚至可能吗?

Thanks谢谢

I do not believe this is feasible.我不相信这是可行的。 Web servers exists just for this reason: to serve HTML pages to clients . Web 服务器的存在正是出于这个原因:为客户端提供 HTML 页面 Amazon S3 exists for file storage, such as images, videos, js files, css files, fonts etc. Not HTML! Amazon S3用于文件存储,例如图像、视频、js 文件、css 文件、字体等。不是 HTML!

On the other hand, suppose this was feasible, your Web server should make a GET request to the HTML stored in S3 (to get the html), then fill it with context variables and then send it to the client ( response ).另一方面,假设这是可行的,您的 Web 服务器应该向存储在 S3 中的 HTML 发出GET request (以获取 html),然后用上下文变量填充它,然后将其发送到客户端( response )。

The job of a Django view is to take a Web request and return a Web response . Django 视图的工作是take a Web request and return a Web response Not making another GET request to get the html which will send as a respose right away (!).不发出另一个GET请求来获取将立即作为respose发送的 html (!)。

Hope that clarifies your question!希望能澄清你的问题!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM