Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
Is there a way to make all pages in a Flask app show the same content?

I'm working on a Flask app and I wanted to add a custom maintenance mode page controlled using a variable. Is there a way I can do this besides creating if-then statements checking if the variable is true: E.g. what I would do:

@app.route("/mypage")
def mypage():
  if (maintenance_mode == 1):
      return render_template("maintenance.html")
  return "response"

I'd like to do this without using an if-then statement and preferably just use 1 @app.route.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You might not even need flask for this and can control it on other levels, but for flask here are good examples to do so.

It is suggested to add @app.before_request and check maintenance flag. (@app.before_request will be called before all request, so you do not need to do maintenance check for all 50 routes).

@app.before_request
def check_under_maintenance():
    if maintenance_mode == 1:  #this flag can be anything, read from file,db or anything
        abort(503) 

@app.route('/')
def index():
    return "This is Admiral Ackbar, over"

@app.errorhandler(503)
def error_503(error):
    return render_template("maintenance.html") 
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda