Add basic 404 handler
This commit is contained in:
parent
94d3ee5d2a
commit
d73a6b7730
1 changed files with 7 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
from sanic import Sanic
|
||||
from sanic.response import json
|
||||
from sanic.response import json, text
|
||||
from sanic.exceptions import NotFound
|
||||
|
||||
app = Sanic()
|
||||
|
||||
|
@ -8,5 +9,10 @@ async def test(request):
|
|||
return json({"hello": "world"})
|
||||
|
||||
|
||||
@app.exception(NotFound)
|
||||
def ignore_404s(request, exception):
|
||||
return text("Page not found at {}".format(request.url), status=404)
|
||||
|
||||
|
||||
def main():
|
||||
app.run(host="0.0.0.0", port="8000")
|
||||
|
|
Reference in a new issue