Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

344
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda