【问题标题】:django-rest returning http 301 status code when calling http delete without trailing slashdjango-rest 在调用 http 删除时返回 http 301 状态码而没有斜杠
【发布时间】:2019-08-14 14:41:33
【问题描述】:

我最近在django rest框架上体验到,在发出删除请求时会返回http 301状态码,而当trailing_slash=True时,url中不包含斜杠。虽然缺少 post 请求的尾部斜杠会返回运行时错误。所以我的问题是,这是一个错误还是预期的行为?

【问题讨论】:

  • 通常,对于 REST API,特定对象的 URL没有 尾部有斜杠:/objects/,这样可以可以预期我会说。 PUT 和 DELETE 用于特定对象,不需要尾部斜杠。对象列表确实有尾部斜杠 (/objects/),因此创建新对象的 POST 请求需要尾部斜杠。

标签: django django-rest-framework


【解决方案1】:

301 是预期的,因为 Django 将您重定向到带有斜杠的 URL,因为您有 trailing_slash=True。如果您想更改,请参阅APPEND_SLASH settings

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 2014-02-08
    • 1970-01-01
    • 2015-02-16
    • 2019-07-15
    • 1970-01-01
    • 2020-09-26
    相关资源
    最近更新 更多