Python 重定向到404错误页面
是否可以重定向到404和500上的页面,而不是构建自定义响应?我试过了-Python 重定向到404错误页面,python,google-app-engine,http-status-code-404,Python,Google App Engine,Http Status Code 404,是否可以重定向到404和500上的页面,而不是构建自定义响应?我试过了- class NotFoundPageHandler(webapp.RequestHandler): def get(self): #if 400 self.redirect('error/notfound.html') #if 500 how to check def main(): application = webapp.WSGIAppl
class NotFoundPageHandler(webapp.RequestHandler):
def get(self):
#if 400
self.redirect('error/notfound.html')
#if 500 how to check
def main():
application = webapp.WSGIApplication(
[
('/', MainPage),
('/index.html', MainPage),
('.*', NotFoundPageHandler)
], debug=True)
但它不起作用 您不想重定向。您需要的是自定义错误页
-error\u code:404
或-error\u code:500
也可以。仔细阅读该链接,听起来你必须小心那些文件不在静态文件目录中。我已经浏览了它并将其添加到了我的yaml文件中。但是,即使文件路径正确,这也不起作用。是否删除了('.*',NotFoundPageHandler)
?您确定没有与静态文件目录重叠吗?如果那不起作用,我不知道还能尝试什么。是的,我确实把它扔掉了。我将未找到的文件从根目录移动到一个新文件夹,该文件夹不在静态目录中。还是不走运(请,请不要这样做。出现错误时,提供适当的错误代码,不要将用户重定向到“错误”页面。这会破坏互联网。
error_handlers:
- file: default_error.html
- error_code: over_quota
file: over_quota.html