This line is causing crashes.  "IndexError: list index out of range".  It is not consistently reproducible, but seems to happen when you direct back to the index page from the form or image page.  One time it happened when the page first loaded.  You should probably check whether something exists before trying to index into it, and avoid re-using the same variable to mean so many different things.