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

343
Views
How do I disable Flask 308 redirect for trailing slash?

I have such endpoints

@app.route('/values', methods=['GET', 'POST'])
def operation_types():
    return '', 200


@app.route('/values/', methods=['GET', 'DELETE', 'PUT'])
@app.route('/values/<code>', methods=['GET', 'DELETE', 'PUT'])
def operation_type_(code: str = ''):
    if request.method == 'GET':
        return '', 200
    if request.method == 'DELETE':
        return '', 200
    if request.method == 'PUT':
        return '', 201
    return '', 405

I want the app to behave like this

GET /values         # lists all values
POST /values        # adds a new value

GET /values/123     # gets a value
DELETE /values/123  # deletes a value
PUT /values/123     # updates a value

and I also want this, to be treated as the later:

GET /values/        # gets a value with code ""
DELETE /values/     # deletes a value with code ""
PUT /values/        # updates a value with code ""

In any other case I want to get 404 if the route is missing, or 405 if method is not allowed.

But here's my problem:

DELETE  /values  # this should return 405, because method isn't allowed for /values, only for /values/

But instead I get 308, with Location: header redirecting me to /values/ and also flask renderes wierd HTML body from Werkzeug.

I want to disable this automatic redirect completely, I don't want flask to do any kind of redirects for me.

PS: I tried setting strict_slashes, but then GET /values/ is being mistaken for GET /values. PS: I know I can add DELETE to the first endpoint methods, but that only works for a single endpoint; and I want to set it in the whole application.

over 4 years ago · Santiago Trujillo
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!