简体   繁体   English

使用 Google App Engine 部署 Django API 时访问 static 文件时出现问题

[英]Problem with accessing static files when deploying Django API using Google App Engine

I have schema.yml documentation in the static folder in my project and during development everything seems to be working properly however after deployment to the App Engine I get the error Not Found /static/schema.yml .我在项目的 static 文件夹中有schema.yml文档,在开发过程中一切似乎都正常工作,但是在部署到App Engine后我收到错误Not Found /static/schema.yml My configuration looks in the way shown below.我的配置如下所示。 Do you have any ideas what can be the cause of the problem?你有什么想法可能是问题的原因吗?

settings.py:设置.py:

PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATICFILES_DIRS = (
  os.path.join(BASE_DIR, 'templates'),
)
STATIC_URL = '/static/'

app.yaml: app.yaml:

runtime: custom
env: flex
entrypoint: gunicorn -b :$PORT mysite.wsgi
service: mysite-service

handlers:
- url: /static/
  static_dir: static

Google App Engine Flex for custom environments ignores the handlers section .用于自定义环境的 Google App Engine Flex 会忽略处理程序部分 There are no issues if you add this section to your “app.yaml” but are not used by the environment.如果您将此部分添加到“app.yaml”但环境不使用,则没有问题。 The handlers section is for Google App Engine Standard . handlers 部分适用于Google App Engine Standard So, that is the reason why in the App Engine Standard environment works but not in App Engine flex.因此,这就是为什么在 App Engine 标准环境中有效但在 App Engine flex 中无效的原因。 The only language that supports handlers is java and you can find documentation that says that it is possible to do it.唯一支持处理程序的语言是java ,您可以找到说明可以这样做的文档。

However, in order to serve static files, you can take a look at this doc where it includes the necessary steps to configure static files in App Engine Flex.但是,为了提供 static 文件,您可以查看此文档,其中包含在 App Engine Flex 中配置 static 文件的必要步骤。

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

相关问题 Django 部署未在 Google 应用引擎中加载 static 文件 - Django deployment not loading static files in Google app engine Django static 文件在 Heroku 上使用 ZC5FD214CDD0D2B3B54272E73B0 部署时未加载 - Django static files are not loaded when deploying on Heroku using Docker and Whitenoise Google App引擎:正在部署应用程序,但没有API - Google app engine: Application deploying but no API Google App Engine:仅部署1000个文件的应用程序时,“文件和Blob的最大数量为10000”。 - Google App Engine: getting “Max number of files and blobs is 10000.” when deploying app with only 1000 files 网站未使用Google App Engine Launcher进行部署 - Website not deploying using Google App Engine Launcher 将 Django 应用程序部署到 Google App Engine 时出现错误“ModuleNotFoundError: No module named 'psycopg2'” - Error "ModuleNotFoundError: No module named 'psycopg2'" when deploying Django app to Google App Engine 部署Django应用时的静态文件问题 - Static file issue when deploying an Django app 如何在谷歌应用引擎上提供静态文件 - how to serve static files on google app engine 静态文件在Google App Engine中位于哪里? - Where are the static files located in google app engine? 带有静态文件的Google App Engine服务 - Google App Engine service with static files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM