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

206
Views
Raise 404 if Flask catch-all route starts with prefix

I am using the catch-all url pattern in my Flask route. I want the view to ignore (throw a 404 error) any path that starts with /api. How can I do this?

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def index(path):
    return 'Hello, World!'
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Check if the route starts with the prefix, then cancel if it does.

 from flask import abort if path.startswith('api'): abort(404)
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!