Google AppEngine自定义404动态页面
我想在 /dev/ path 中设置自定义 404 页面和管理区域,所以我有这个 app.yaml:
application: appengine_app
version: 0-00-1
runtime: python
api_version: 1
handlers:
- url: /dev/.*
script: dispatch.py
login: admin
- url: /.*
script: dispatch.py
使用下一个代码
app = webapp.WSGIApplication( [ ('/dev/analyze', AnalyzePage)
, ('/.*', NotFoundPage) ]
, debug=False )
在本地计算机上一切正常。但是,当我尝试在生产服务器上获取 /dev/analyze 时,它会重定向到 /_ah/login_required?continue=http://appengine_app.appspot.com/dev/analyze它被 NotFoundPage 捕获。所以我不能在生产中使用管理部分。我可以拥有动态 404 页面和网站的管理部分吗?
UPD:如果我关闭 NotFoundPage 并尝试在生产服务器上获取 /dev/analyze,它会重定向到 /_ah/login_required?continue=http://appengine_app .appspot.com/dev/analyze 并响应 404 错误
I want to set custom 404 page and admin zone in /dev/ path , so I have this app.yaml:
application: appengine_app
version: 0-00-1
runtime: python
api_version: 1
handlers:
- url: /dev/.*
script: dispatch.py
login: admin
- url: /.*
script: dispatch.py
with next code
app = webapp.WSGIApplication( [ ('/dev/analyze', AnalyzePage)
, ('/.*', NotFoundPage) ]
, debug=False )
On local machine all is ok. But when I try to GET /dev/analyze on Production server it redirects to /_ah/login_required?continue=http://appengine_app.appspot.com/dev/analyze and it catched by NotFoundPage. So I can not use admin part on Production. Can I has dynamic 404 page and admin part of site?
UPD: if I switch off NotFoundPage and try to GET /dev/analyze on Production server it redirects to /_ah/login_required?continue=http://appengine_app.appspot.com/dev/analyze and response with 404 error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已将
app.yaml
中的脚本句柄设置为仅限管理员,这意味着运行时将确保您在向代码发送请求之前以管理员身份登录。运行时无法知道该页面将导致 404 - 而且这可能是您甚至不希望非管理员用户发现的东西。如果向未登录的用户发送 404 很重要,您可以使 app.yaml 中的处理程序更加具体 - 例如,使其仅匹配
/dev/analyze
- 或者您可以将管理检查转移到您的代码中。You've set the script handle in
app.yaml
to admin-only, which means the runtime will ensure you're logged in as an admin before it sends requests to your code. There's no way for the runtime to know that the page will result in a 404 - and this is plausibly something you may not even want non-admin users to discover.If it's important that you send 404s to users who aren't signed in, you can either make the handler in app.yaml more specific - eg, make it match only
/dev/analyze
- or you can shift the admin check into your code.