Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #22 from datnguyen0606/Handling-non-existing-entity

display 404 page when accessing wrong url
  • Loading branch information...
commit 3edb05fc1c13a1c16f796ea77139e2df454eef18 2 parents d35db9b + 516a05e
@brendonh authored
Showing with 20 additions and 4 deletions.
  1. +16 −4 warp/crud/render.py
  2. +4 −0 warp/templates/error_404.mak
View
20 warp/crud/render.py
@@ -142,9 +142,18 @@ def _getViewTemplate(self):
_getEditTemplate = _getViewTemplate
+ def getRequestObject(self, request):
+ try:
+ objID = int(request.resource.args[0])
+ except Exception:
+ return None
+ return request.store.get(self.model, objID)
+
def render_view(self, request):
- objID = int(request.resource.args[0])
- obj = request.store.get(self.model, objID)
+ obj = self.getRequestObject(request)
+ if obj is None:
+ template = templateLookup.get_template("/error_404.mak")
+ return helpers.renderTemplateObj(request, template)
return helpers.renderTemplateObj(request,
self._getViewTemplate(),
@@ -154,8 +163,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.getRequestObject(request)
+ if obj is None:
+ 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.