fix: add notfound()
View method; auto-append trailing slash
the latter provides auto-redirect to `/widgets/` when user visits `/widgets` for example
This commit is contained in:
parent
9a739381ae
commit
7766ca6b12
3 changed files with 17 additions and 2 deletions
|
@ -73,6 +73,14 @@ class View:
|
|||
"""
|
||||
return forms.Form(self.request, **kwargs)
|
||||
|
||||
def notfound(self):
|
||||
"""
|
||||
Convenience method, to raise a HTTP 404 Not Found exception::
|
||||
|
||||
raise self.notfound()
|
||||
"""
|
||||
return httpexceptions.HTTPNotFound()
|
||||
|
||||
def redirect(self, url, **kwargs):
|
||||
"""
|
||||
Convenience method to return a HTTP 302 response.
|
||||
|
|
|
@ -53,7 +53,10 @@ class CommonView(View):
|
|||
@classmethod
|
||||
def _defaults(cls, config):
|
||||
|
||||
# home
|
||||
# auto-correct URLs which require trailing slash
|
||||
config.add_notfound_view(cls, attr='notfound', append_slash=True)
|
||||
|
||||
# home page
|
||||
config.add_route('home', '/')
|
||||
config.add_view(cls, attr='home',
|
||||
route_name='home',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue