aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormjfernez <mjf@mjfer.net>2022-02-03 00:31:01 -0500
committermjfernez <mjf@mjfer.net>2022-02-03 00:31:01 -0500
commit2805900e8fa008936f996c5986a9a1f31c6c0f50 (patch)
tree63869c6d8e59a24226f609e4b7b716f3ebe7208c
parent2c0179493a0b11b97e4b04f376665429b44f8398 (diff)
downloadezcms-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
-rw-r--r--views.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/views.py b/views.py
index 4a41248..3393cb2 100644
--- a/views.py
+++ b/views.py
@@ -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,