Question

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?

Was it helpful?

Solution 2

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)

OTHER TIPS

You may want to try creating the file "missing.html" at the top level.

source: http://wiki.dreamhost.com/Creating_custom_error_pages

Edit: To setup an error handling page from Flask itself, you do this:

from flask import render_template

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

See: http://flask.pocoo.org/docs/patterns/errorpages/

My thought is that you are getting the 500 error because Flask/Python is crashing. Do you have debugging turned on? How is your routing setup?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top