eudicots / Cactus

Static site generator for designers. Uses Python and Django templates.
BSD 3-Clause "New" or "Revised" License
3.47k stars 313 forks source link

with "prettify" on error.html handling doesn't work #160

Closed elguavas closed 9 years ago

elguavas commented 9 years ago

if i have prettify on, when i try an url that should get a 404 i instead get an exception in the console.

an example exception (with path starts elided) is:

Uncaught exception in write_error
Traceback (most recent call last):
  File ".../virtualenv/cactus/lib/python2.7/site-packages/tornado/web.py", line 976, in send_error
    self.write_error(status_code, **kwargs)
  File ".../virtualenv/cactus/lib/python2.7/site-packages/cactus/server.py", line 61, in write_error
    return self.render("error.html")
  File ".../virtualenv/cactus/lib/python2.7/site-packages/tornado/web.py", line 704, in render
    html = self.render_string(template_name, **kwargs)
  File ".../virtualenv/cactus/lib/python2.7/site-packages/tornado/web.py", line 808, in render_string
    t = loader.load(template_name)
  File ".../virtualenv/cactus/lib/python2.7/site-packages/tornado/template.py", line 343, in load
    self.templates[name] = self._create_template(name)
  File ".../virtualenv/cactus/lib/python2.7/site-packages/tornado/template.py", line 370, in _create_template
    with open(path, "rb") as f:
IOError: [Errno 2] No such file or directory: u'.../.build/error.html'
elguavas commented 9 years ago

btw this is when viewing the site via cactus serve.

fedelibre commented 9 years ago

duplicate of issue #84 and I think I reported the same but can't find it right now

fedelibre commented 9 years ago

@elguavas it should happen also when you build it

I made this "stupid" change to make things work in my configuration:

diff --git a/cactus/server.py b/cactus/server.py
index 2c8588a..e194272 100644
--- a/cactus/server.py
+++ b/cactus/server.py
@@ -58,7 +58,7 @@ class StaticHandler(tornado.web.StaticFileHandler):
     def write_error(self, status_code, **kwargs):

         if status_code == 404:
-            return self.render("error.html")
+            return self.render("error/index.html")

         return super(StaticHandler, self).write_error(status_code, **kwargs)
-- 

But of course it should check if prettify is true and render the right file path.

elguavas commented 9 years ago

thanks fedelibre, at least i know it's a known issue and can hack around it for now.

krallin commented 9 years ago

Thanks for the report! Here's a fix:

https://github.com/koenbok/Cactus/commit/98e481c132cc49215fb8281ed55061c7a97bbf6e

(note: I haven't made a PyPi release with this yet, so you'd have to install from master to get the fix)

Cheers