The HTTPFound seems to be hard-coded in AppendSlashNotFoundViewFactory
, but you may use its code as an inspiration for your "not found view":
from pyramid.interfaces import IRoutesMapper
from pyramid.compat import decode_path_info
@notfound_view_config(renderer="not_found.mako")
def notfound(request):
path = decode_path_info(request.environ['PATH_INFO'] or '/')
registry = request.registry
mapper = registry.queryUtility(IRoutesMapper)
if mapper is not None and not path.endswith('/'):
slashpath = path + '/'
for route in mapper.get_routes():
if route.match(slashpath) is not None:
qs = request.query_string
if qs:
qs = '?' + qs
raise HTTPMovedPermanently(location=request.path+'/'+qs)
return {}
(untested, treat as pseudocode)