From 111e5e57bb92085e05973d0a103bc78e2417cf6a Mon Sep 17 00:00:00 2001 From: Daniel Grams Date: Wed, 24 Feb 2021 15:44:20 +0100 Subject: [PATCH] Missing robots.txt causes internal server error #129 --- project/__init__.py | 6 ++++-- project/templates/_macros.html | 2 +- project/views/root.py | 15 ++++----------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/project/__init__.py b/project/__init__.py index 217521b..4dea175 100644 --- a/project/__init__.py +++ b/project/__init__.py @@ -56,8 +56,10 @@ cache_path = ( ) dump_path = os.path.join(cache_path, "dump") img_path = os.path.join(cache_path, "img") -sitemap_path = os.path.join(cache_path, "sitemap.xml") -robots_txt_path = os.path.join(cache_path, "robots.txt") +sitemap_file = "sitemap.xml" +robots_txt_file = "robots.txt" +sitemap_path = os.path.join(cache_path, sitemap_file) +robots_txt_path = os.path.join(cache_path, robots_txt_file) # i18n app.config["BABEL_DEFAULT_LOCALE"] = "de" diff --git a/project/templates/_macros.html b/project/templates/_macros.html index 106f3a6..373ea0e 100644 --- a/project/templates/_macros.html +++ b/project/templates/_macros.html @@ -233,7 +233,7 @@ {% if link %}
- {{ link }} + {{ link }}
{% endif %} {% endmacro %} diff --git a/project/views/root.py b/project/views/root.py index ad8a53e..a86a33c 100644 --- a/project/views/root.py +++ b/project/views/root.py @@ -1,18 +1,11 @@ import json import os.path -from flask import ( - redirect, - render_template, - request, - send_file, - send_from_directory, - url_for, -) +from flask import redirect, render_template, request, send_from_directory, url_for from flask_babelex import gettext from markupsafe import Markup -from project import app, dump_path, robots_txt_path, sitemap_path +from project import app, cache_path, dump_path, robots_txt_file, sitemap_file from project.services.admin import upsert_settings from project.views.utils import track_analytics @@ -97,9 +90,9 @@ def static_from_root(): @app.route("/robots.txt") def robots_txt(): - return send_file(robots_txt_path) + return send_from_directory(cache_path, robots_txt_file) @app.route("/sitemap.xml") def sitemap_xml(): - return send_file(sitemap_path) + return send_from_directory(cache_path, sitemap_file)