英文:
Why isn't it recommended to use bare HTTP status codes in a response?
问题
根据Django REST Framework的文档,"在响应中使用裸状态代码不建议"。他们建议使用status
模块中的对象(例如status.HTTP_404_NOT_FOUND
)。我的问题是,这个建议是从哪里来的?我找不到任何类似的"官方"来源来支持这个建议。
英文:
According to the documentation for Django REST Framework, "using bare status codes in your responses isn't recommended". They recommend instead using the objects from the status
module (e.g. status.HTTP_404_NOT_FOUND
). My question is, where does this recommendation come from? I wasn't able to find any kind of 'official' source for this recommendation.
答案1
得分: 3
这个建议来自于那份文件,但是它基于避免使用魔法数等概念。
在Django Rest Framework中,这些状态的命名方式(来源)使开发人员阅读代码时更容易理解和记住代码代表的含义,而不必记住或双重检查每个数字所指代的内容。
英文:
The recommendation comes from that document but it's based on concepts like avoiding magic numbers.
With the way these statuses are named in Django Rest Framework (source) makes it easier for the developer reading the code to understand and remember what the code represents rather than having to remember or double check what each number refers to.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论