From 4e8799eca5a0e8f9d332a86e26b59d1fe77e8d72 Mon Sep 17 00:00:00 2001 From: Happilands <49983499+Happilands@users.noreply.github.com> Date: Thu, 27 Oct 2022 19:29:50 +0200 Subject: [PATCH] Add robots.txt file From https://www.pythonanywhere.com/forums/topic/2899/ --- app/app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/app.py b/app/app.py index c2d9e05..f42104e 100755 --- a/app/app.py +++ b/app/app.py @@ -8,7 +8,7 @@ from datetime import datetime from logging.handlers import TimedRotatingFileHandler from admin import init_admin -from flask import Flask, render_template +from flask import Flask, render_template, Response from flask_bootstrap import Bootstrap, StaticCDN from flask_debugtoolbar import DebugToolbarExtension from flask_login import LoginManager @@ -158,6 +158,12 @@ def create_app(): """Initializer for the Flask app object""" app = Flask(__name__) + @app.route('/robots.txt') + def noindex(): + r = Response(response="User-Agent: *\nDisallow: /\n", status=200, mimetype="text/plain") + r.headers["Content-Type"] = "text/plain; charset=utf-8" + return r + # Load the config file app.config.from_object("config.Configuration")