简体   繁体   English

Flask-Frozen:如何生成404页面?

[英]Flask-Frozen: How to generate a 404 page?

I am trying to generate a 404 page for my Flask-Frozen application. 我正在尝试为Flask-Frozen应用程序生成404页面。 Currently, this is my only error-handling logic in views.py 目前,这是我在views.py中唯一的错误处理逻辑

@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404

Apparently, that isn't enough code to do the trick, any suggestions? 显然,这还不足以解决问题,有什么建议吗?

There are two things you need to do: 您需要做两件事:

  1. Add a call to freezer.register_generator that returns at least one URL that will result in your 404 page: 添加对freezer.register_generator的调用,该调用至少返回一个将在404页面中显示的URL:

     @freezer.register_generator def error_handlers(): yield "/404" 
  2. Setup your web server to respond to 404 errors with your static page (the example is for Apache): 设置您的Web服务器以使用您的静态页面来响应404错误(该示例适用于Apache):

     ErrorDocument 404 /404.html 

You're using Frozen-Flask which freezes the site to serve it statically. 您正在使用Frozen-Flask ,它会冻结站点以静态方式为其提供服务。 There's no way to handle static pages in a static site unless you configure your webserver to serve a specific page in case of error. 除非将Web服务器配置为在出现错误的情况下提供特定页面,否则无法处理静态站点中的静态页面。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM