PEP8 and template path fix

- Template directory path based on file location
- Minor code reformatting based on PEP8
- Switched to 'in' from depricated has_key
- Define IOError instead of broad except