我有一个简单的Flask应用程序。
在本地主机上,Flask会使用尾部斜杠重定向到规范网址。因此,如果我访问localhost:8080/test
,则会转到localhost:8080/test/
但是,当我部署到谷歌应用引擎时,
我试试***.appspot.com/test
,它只返回404错误。
它不会使用尾部斜杠重定向到规范URL。
我真的无法弄清楚问题。我使用gae-init https://github.com/gae-init/gae-init
这是我的app.yaml文件
service: default
instance_class: F1
runtime: python27
api_version: 1
threadsafe: true
builtins:
- appstats: on
- deferred: on
- remote_api: on
inbound_services:
- warmup
libraries:
- name: ssl
version: latest
error_handlers:
- file: templates/error_static.html
handlers:
- url: /favicon.ico
static_files: static/img/favicon.ico
upload: static/img/favicon.ico
- url: /robots.txt
static_files: static/robots.txt
upload: static/robots.txt
- url: /p/(.*\.ttf)
static_files: static/\1
upload: static/(.*\.ttf)
mime_type: font/ttf
expiration: "365d"
- url: /p/(.*\.woff2)
static_files: static/\1
upload: static/(.*\.woff2)
mime_type: font/woff2
expiration: "365d"
- url: /p/
static_dir: static/
expiration: "365d"
- url: /.*
script: main.app
secure: always
redirect_http_response_code: 301
skip_files:
- ^(.*/)?#.*#
- ^(.*/)?.*/RCS/.*
- ^(.*/)?.*\.bak$
- ^(.*/)?.*\.py[co]
- ^(.*/)?.*~
- ^(.*/)?Icon\r
- ^(.*/)?\..*
- ^(.*/)?app\.yaml
- ^(.*/)?app\.yml
- ^(.*/)?index\.yaml
- ^(.*/)?index\.yml
- ^lib/.*
- ^static/dev/.*
- ^static/ext/.*\.coffee
- ^static/ext/.*\.css
- ^static/ext/.*\.js
- ^static/ext/.*\.less
- ^static/ext/.*\.json
- ^static/src/.*
以下是我处理测试的方法
@app.route('/test/')
@auth.login_required
def contact_list():
contact_dbs, contact_cursor = model.Contact.get_dbs(
user_key=auth.current_user_key(),
)
return flask.render_template(
'contact_list.html',
html_class='contact-list',
title='Contact List',
contact_dbs=contact_dbs,
next_url=util.generate_next_url(contact_cursor),
)
The console log is
2018-06-14 02:45:09.388 JST
301 - Moved Permanently: https://ktest321986.appspot.com/contact (/base/data/home/apps/b~ktest321986/20180613t165904.410404733871213095/control/error.py:29)
2018-06-14 02:45:09.389 JST
301 Moved Permanently: None (/base/data/home/apps/b~ktest321986/20180613t165904.410404733871213095/control/error.py:31)
Traceback (most recent call last):
File "lib.zip/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "lib.zip/flask/app.py", line 1791, in dispatch_request
self.raise_routing_exception(req)
File "lib.zip/flask/app.py", line 1774, in raise_routing_exception
raise request.routing_exception
RequestRedirect: 301 Moved Permanently: None
你可以在这里试试: 不起作用:https://ktest321986.appspot.com/contact 工作:https://ktest321986.appspot.com/contact/
答案 0 :(得分:0)
我不知道这是什么问题。 但是,当我从Mac部署项目时,问题就消失了。 如果我从窗口10部署项目,则会出现问题。 真有趣!