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

345
Vistas
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
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