raise HTTP handlers

82 views
Skip to first unread message

Jacinto Parga

unread,
Dec 7, 2023, 3:53:53 PM12/7/23
to py4web
I have made a 404 error handler in __init__.py that works fine: 

@ombott.error(404, "/<params:path>")
def error404(route, params):
    entrada = str(route)
    ombott.response.status = 404
    return """
    <!doctype html>
    <html lang="en">
        <head>
            <meta charset="UTF-8" />
            <title>Not Found</title>
            <link rel="icon" type="image/ico"  href="/static/favicon.ico">
        </head>
        <body>
        <div align='center'>
        <h2 style="text-align:center;font-family:monospace;">404 Not Found</h2>
        <p style="text-align:center;font-family:monospace;">{}</p>
        <a href="/index">
        <button type="button">Inicio</button></a>
        </div>
        </body>
    </html>
    """.format(
        entrada
    )


I tried to do the same with 500 and 403 exceptions but with 500 the default page of py4web arises and a blank page with 403. 

Have anyone done it? Is there any way to route the raise HTTP(code) to a specific controller?

Thanks

CarlosDB

unread,
Jun 10, 2025, 8:49:40 AM6/10/25
to py4web
Hi,
I'm in the same situation trying to handle the 403 error.
Has anyone managed to solve this?
Thanks!!!
Reply all
Reply to author
Forward
0 new messages