我在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:
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:
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)
更多推荐
发布评论