Python 谷歌appengine中的Html 301重定向
我正在用python在google appengine上主持一个网页。我有单独的网页,在目录中,我需要知道如何重定向,例如:“www.example.com/page”。当我不在页面后面添加另一个“/”时,它会显示“404未找到”。如何更改重定向脚本以添加此脚本?这是我的app.yaml:Python 谷歌appengine中的Html 301重定向,python,html,google-app-engine,redirect,Python,Html,Google App Engine,Redirect,我正在用python在google appengine上主持一个网页。我有单独的网页,在目录中,我需要知道如何重定向,例如:“www.example.com/page”。当我不在页面后面添加另一个“/”时,它会显示“404未找到”。如何更改重定向脚本以添加此脚本?这是我的app.yaml: application: example-app version: 4 runtime: python api_version: 1 handlers: -
application: example-app
version: 4
runtime: python
api_version: 1
handlers:
- url: (.*)/
static_files: static\1/index.html
upload: static/index.html
- url: /
static_dir: static
- url: /apps/(.*\.apk)
mime_type: application/vnd.android.package-archive
static_files: static/apps/\1
upload: static/apps/(.*\.apk)
- url: (.*)/apps
script: directory.py
- url: /comingsoon
script: DirecotryHandler.py
- url: /directory
script: DirecotryHandler.py
这是我的directoryhandler.py:
import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class DirecotryHandler(webapp.RequestHandler):
def get(self, tail):
if tail == î:
self.redirect(ë/directory/í, permanent=True)
#TODO: respond to ì/directory/î request
def head(self, tail):
if tail == î:
self.redirect(ë/directory/í, permanent=True)
#TODO: respond to ì/directory/î request
application = webapp.WSGIApplication(
[
(r'^/directory(/?)$', DirectoryPage),
])
def main():
run_wsgi_app(application)
if __name__ == ì__main__î:
main()
如何编辑DirectryHandler.py以处理301重定向?提前感谢您的帮助 实际上,是您的浏览器处理301重定向。您的代码只是缺少生成301重定向的路径
(r'^/comingsoon$',DirecotryHandler),
然后,当浏览器调用www.example.com/comingsoon
时,您的DirecotryHandler类处理请求并调用self.redirect(“/directory/”,permanent=True)
。这将生成301重定向作为对浏览器的响应,浏览器会看到新的URL/directory/
并请求它,从而调用您的DirectoryPage
类