Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!