简体   繁体   English

使用App Engine Python 37在没有任何Python脚本的情况下提供静态文件

[英]Serving static files with App Engine Python 37 without any Python script

With App Engine Python27(standard env), it was possible to create a webapp that only serves static resources from the app.yaml . 使用App Engine Python27(标准env),可以创建仅提供来自app.yaml静态资源的webapp。 Without writing any Python script. 无需编写任何Python脚本。

With Python37 (standard env), I see that it's still possible to have the static_dir in the handlers section of app.yaml but I'm wondering if this will work the same way. 使用Python37(标准环境),我发现仍然有可能在app.yamlhandlers部分中包含static_dir ,但我想知道这是否可以相同的方式工作。 Cause I don't define any entrypoint, I don't set a webserver. 原因我没有定义任何入口点,也没有设置Web服务器。 I have only the app.yaml at the moment. 我目前只有app.yaml

And the first that blocks me at the moment: if doing so, how do I locally run this app ? 目前,第一个阻止我的是:如果这样做,我如何在本地运行此应用程序? (no Python script so no python main.py and dev_appserver.py does not work for Python37). (没有Python脚本,因此python main.pydev_appserver.py不适用于Python37)。

Thanks for your answers 谢谢你的回答

Yes, the static_dir and static_file configurations work the same way, their sections in the app.yaml reference docs for 2.7 and 3.7 are identical except for the references to the 2.7-specific application_readable option. 是的, static_dirstatic_file配置以相同的方式工作,在app.yaml参考文档2.73.7中,它们的部分相同,但对2.7特定的application_readable static_file选项的引用除外。

Since serving the static content on GAE is identical (the static content is uploaded and served separately from the application code - equivalent, if you want, to serving from a CDN) it doesn't really matter if you're using the 2.7 runtime or the 3.7 one - you're not actually executing any python code, right? 由于在GAE上提供静态内容是完全相同的(静态内容与应用程序代码分开上传和提供-如果需要,与从CDN提供的内容相当),如果您使用的是2.7运行时或3.7版本-您实际上并没有执行任何python代码,对不对?

So one option would be to just use 2.7 instead (adding a minimal app skeleton to keep the runtime happy, say by just returning 404 or redirecting to one of the static pages - you can get it from the Quickstart ). 因此,一种选择是仅使用2.7(添加最小的应用程序框架以使运行时保持快乐,例如,只需返回404或重定向到静态页面之一-您可以从Quickstart中获得它)。 You can then continue to use the 2.7 development server for local execution. 然后,您可以继续使用2.7开发服务器进行本地执行。

Another option would be to use 2.7 (as in option 1) just for local development, but switch back to 3.7 for deployment (ie update the app.yaml file, drop the skeleton app code or update it for 3.7). 另一个选择是仅将2.7(与选项1相同)用于本地开发,但切换回3.7进行部署(即更新app.yaml文件,删除框架应用代码或将其更新为3.7)。 A bit more tedious and brittle, but it can be done. 有点乏味和脆弱,但是可以做到。

A 3rd option would be to try the updated development server which has some limited support for 3.7, see Python 3.7 Local Development Server Options for new app engine apps . 第三种选择是尝试使用更新的开发服务器,该服务器对3.7的支持有限,请参阅Python 3.7本地开发服务器选项以了解新的App Engine应用 Serving static content might be included in that limited support. 有限的支持中可能包含提供静态内容。 You'd need to meet its specific requirements. 您需要满足其特定要求。 You'd also need a 3.7-compatible skeleton app, you can get one from the 3.7 Quickstart . 您还需要一个与3.7兼容的框架应用程序,可以从3.7 Quickstart中获得一个。

Finally, you could also use some other tool locally during development, if you have one (same advice as for running an actual app locally ). 最后,如果您有一个工具,也可以在开发过程中在本地使用其他工具(与在本地运行实际应用程序的建议相同)。 It could simply be your browser for static-only content :) Again, the goal is to just develop your static content, GAE will serve it the same way. 它可能只是您的静态纯内容浏览器:)同样,目标是仅开发静态内容,GAE将以相同的方式提供内容。 You won't need any skeleton app in this case. 在这种情况下,您不需要任何骨架应用程序。

Side note: I saw this in the Node.js standard env app.yaml reference , not sure if it's applicable to python 3.7 as well, just be aware of it: 旁注:我在Node.js标准env app.yaml参考中看到了这一点,不确定它是否也适用于python 3.7,请注意:

In order to use static handlers, at least one of your handlers must contain the line script: auto to deploy successfully. 为了使用静态处理程序,您的至少一个处理程序必须包含以下行脚本:auto才能成功部署。

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

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