Ricardo

Django 与 DRF allowed_methods 源码笔记

阅读时长: 1 分钟

allowed_methods

Python
1
2
3
4
5
6
7
8
class APIView(View):
  ...
    @property
    def allowed_methods(self):
        """
        Wrap Django's private `_allowed_methods` interface in a public property.
        """
        return self._allowed_methods()
Python
1
2
    def _allowed_methods(self):
        return [m.upper() for m in self.http_method_names if hasattr(self, m)]
Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
class View:
    """
    Intentionally simple parent class for all views. Only implements
    dispatch-by-method and simple sanity checking.
    """

    http_method_names = [
        "get",
        "post",
        "put",
        "patch",
        "delete",
        "head",
        "options",
        "trace",
    ]
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
记录自己
Built with Hugo
主题 Stack 由 Jimmy 设计