Dreamhost上的Flask 404(Flask 404 on Dreamhost)

编程入门 行业动态 更新时间:2024-10-03 21:30:40
Dreamhost上的Flask 404(Flask 404 on Dreamhost)

我在Dreamhost上使用Flask。 我(大部分)都按照这里发布的说明https://mattcarrier.com/flask-dreamhost-setup/ 。 我能够成功设置页面并将URL直接指向这些页面等。

现在我希望能够设置404页面。 我使用@ app.errorhandler设置错误处理程序。 唯一的问题是,如果我转到任何没有设置URL的页面,它只返回一个标准的Apache 500错误页面。 这是因为Dreamhost如何设置Apache? 公共(静态)文件夹位于顶层。 我怎样才能解决这个问题?

I am using Flask on Dreamhost. I (mostly) followed the instruction posted here https://mattcarrier.com/flask-dreamhost-setup/. I was able to successfully set up pages and direct urls to those pages, etc.

Now I want to be able to set a 404 page. I set the error handler using @app.errorhandler. The only problem is that it just returns a standard Apache 500 error page if I go to any page that doesn't have a URL set. Is this because of how Dreamhost has Apache setup? The public (static) folder is at the top level. How can I fix this?

最满意答案

您可能想尝试在顶层创建文件“missing.html”。

来源: http : //wiki.dreamhost.com/Creating_custom_error_pages

编辑:要从Flask本身设置错误处理页面,请执行以下操作:

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

请参阅: http : //flask.pocoo.org/docs/patterns/errorpages/

我的想法是你得到了500错误,因为Flask / Python崩溃了。 你有打开调试吗? 您的路由设置如何?

I found the answer here - http://blog.tuxcoder.com/2011/9/8/dreamhost_python_wsgi/

If you plan to do any active development on the Dreamhost side, this step will simplify your efforts. Werkzeug comes with a really nice debugging engine, but it does not work with the Dreamhost configuration by default. or example, if you have a simple Python coding error in your app, it will result in the following:

default error page of werkzeug

In this mode, you're out of luck. The only option is to startup a local server where you can go back and test the app. In some cases it might be a big effort just to replicate the bug.

With the Werkzeug Debugger enabled and patched, you'll get a much nicer output:

werkzeug debugger

Here is what it says on the Dreamhost Wiki http://wiki.dreamhost.com/Flask (in passenger_wsgi.py:

# Uncomment next two lines to enable debugging # from werkzeug.debug import DebuggedApplication # application = DebuggedApplication(application, evalex=True)

更多推荐

本文发布于:2023-07-09 10:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085592.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Dreamhost   Flask

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!