Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

display 404 page when accessing wrong url

  • Loading branch information...
commit 8a48026af4c7e446f226b1357aaeeadf5c608939 1 parent 8dbce77
@datnguyen0606 datnguyen0606 authored
Showing with 22 additions and 4 deletions.
  1. +18 −4 warp/crud/render.py
  2. +4 −0 warp/templates/error_404.mak
View
22 warp/crud/render.py
@@ -142,9 +142,20 @@ def _getViewTemplate(self):
_getEditTemplate = _getViewTemplate
+ def onMissingObject(self, request):
+ try:
+ objID = int(request.resource.args[0])
+ if isinstance(objID, int):
+ obj = store.get(self.model, objID)
+ return obj
+ except Exception:
+ return None
+
def render_view(self, request):
- objID = int(request.resource.args[0])
- obj = request.store.get(self.model, objID)
+ obj = self.onMissingObject(request)
+ if not obj:
+ template = templateLookup.get_template("/error_404.mak")
+ return helpers.renderTemplateObj(request, template)
return helpers.renderTemplateObj(request,
self._getViewTemplate(),
@@ -154,8 +165,11 @@ def render_view(self, request):
def render_edit(self, request):
- objID = int(request.resource.args[0])
- obj = request.store.get(self.model, objID)
+ obj = self.onMissingObject(request)
+ if not obj:
+ template = templateLookup.get_template("/error_404.mak")
+ return helpers.renderTemplateObj(request, template)
+
crud = self.crudModel(obj)
return helpers.renderTemplateObj(request,
View
4 warp/templates/error_404.mak
@@ -0,0 +1,4 @@
+<%inherit file="/site.mak"/>
+
+<h2>Error 404</h2>
+<div class="error">The requested URL cannot be found.</div>
Please sign in to comment.
Something went wrong with that request. Please try again.