[[ともっくす alloc] init]

ともっくすの雑多な日記と技術的なメモ

Pyramidで404 Not Foundのページを作りたい

デフォルトの場合,Pyramidの404のページは,素っ気ない.

404 Not Found
The resource could not be found.
No such page

こんな感じ.


で,404 Not Foundのページを自分で作りたい.

例えば,こうする.

from pyramid.view import view_config, notfound_view_config

@view_config(route_name="found", renderer="found.pt")
def found_view(request):
    found_text = "Found!!!"
    return dict(found_text=found_text)

@notfound_view_config(renderer="notfound.pt")
def notfound(request):
    notfound_text = "Not Found!!!"
    return dict(notfound_text=notfound_text)

とりあえず,pyramid.viewのnotfound_view_configデコレータを使えばいいっていう,それだけ.