zmiany w wygladzie i nowe funkcje
This commit is contained in:
33
app.py
33
app.py
@ -8,14 +8,8 @@ import markdown as md
|
||||
from flask import abort
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///baza.db'
|
||||
|
||||
app.config['SECRET_KEY'] = 'tajny_klucz'
|
||||
|
||||
# Konfiguracja rejestracji i admina
|
||||
app.config['ALLOW_REGISTRATION'] = False
|
||||
app.config['MAIN_ADMIN_USERNAME'] = 'admin'
|
||||
app.config['MAIN_ADMIN_PASSWORD'] = 'admin'
|
||||
# Ładujemy konfigurację z pliku config.py
|
||||
app.config.from_object('config.Config')
|
||||
|
||||
db = SQLAlchemy(app)
|
||||
login_manager = LoginManager(app)
|
||||
@ -264,8 +258,31 @@ def create_admin_account():
|
||||
db.session.add(main_admin)
|
||||
db.session.commit()
|
||||
|
||||
@app.after_request
|
||||
def add_security_headers(response):
|
||||
if app.config.get("BLOCK_BOTS", False):
|
||||
cache_control = app.config.get("CACHE_CONTROL_HEADER")
|
||||
if cache_control:
|
||||
response.headers["Cache-Control"] = cache_control
|
||||
# Jeśli Cache-Control jest ustawiony, usuwamy Pragma
|
||||
response.headers.pop("Pragma", None)
|
||||
else:
|
||||
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
|
||||
response.headers["Pragma"] = app.config.get("PRAGMA_HEADER", "no-cache")
|
||||
response.headers["X-Robots-Tag"] = app.config.get("ROBOTS_TAG", "noindex, nofollow, nosnippet, noarchive")
|
||||
return response
|
||||
|
||||
|
||||
@app.route('/robots.txt')
|
||||
def robots():
|
||||
if app.config.get("BLOCK_BOTS", False):
|
||||
# Instrukcje dla robotów – blokujemy indeksowanie całej witryny
|
||||
robots_txt = "User-agent: *\nDisallow: /"
|
||||
else:
|
||||
# Jeśli blokowanie botów wyłączone, można zwrócić pusty plik lub inne ustawienia
|
||||
robots_txt = "User-agent: *\nAllow: /"
|
||||
return robots_txt, 200, {'Content-Type': 'text/plain'}
|
||||
|
||||
if __name__ == '__main__':
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
|
Reference in New Issue
Block a user