diff options
author | mjfernez <mjf@mjfer.net> | 2022-02-03 00:31:01 -0500 |
---|---|---|
committer | mjfernez <mjf@mjfer.net> | 2022-02-03 00:31:01 -0500 |
commit | 2805900e8fa008936f996c5986a9a1f31c6c0f50 (patch) | |
tree | 63869c6d8e59a24226f609e4b7b716f3ebe7208c /views.py | |
parent | 2c0179493a0b11b97e4b04f376665429b44f8398 (diff) | |
download | ezcms-2805900e8fa008936f996c5986a9a1f31c6c0f50.tar.gz |
Fix 500 error for missing files
Instead, entering an invalid path will yield a 404 page as expected.
The error was introduced by adding the file_last_modified check before
confirming in the file exists in the render_file function
Diffstat (limited to 'views.py')
-rw-r--r-- | views.py | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -3,7 +3,7 @@ views.py - defines the logic that generates views that a user sees when browsing to certain pages """ import os -from flask import request, send_from_directory, abort +from flask import send_from_directory, abort from flask import render_template, render_template_string, make_response from siteconfig import siteconfig from server import app, cache @@ -49,16 +49,17 @@ def render_file(path): """ if is_hidden_path(path): abort(404) + abs_path = siteconfig.BASE_DIR + path context = default_context() - context.update( - { - 'title': path.split('.')[0].upper(), - 'parent_dir': '/' + '/'.join(path.split('/')[:-1]), - 'last_update': file_last_modified(abs_path), - } - ) if os.path.isfile(abs_path): + context.update( + { + 'title': path.split('.')[0].upper(), + 'parent_dir': '/' + '/'.join(path.split('/')[:-1]), + 'last_update': file_last_modified(abs_path) + } + ) if abs_path.endswith('.html'): with open(abs_path, 'rb') as f: content = f.read().decode("UTF-8") @@ -81,6 +82,8 @@ def render_file(path): dirs, files, links, description = index_dir(abs_path) context.update( { + 'title': path.split('.')[0].upper(), + 'parent_dir': '/' + '/'.join(path.split('/')[:-1]), 'cur_path': path, 'cur_dir': path.split('/')[-1] + '/', 'dirs': dirs, |