账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Flask 源码为什么使用property有些代码不用装饰器方式, 有些又用了?
    22
    0

    最近看到flask的某段源码, 看到一个类定义里面, 有些属性使用了装饰器形式的property写法, 有些却用了property实例化的写法, 这是有什么用途呢?实在看不懂为什么?

        def _get_static_url_path(self):
            if self._static_url_path is not None:
                return self._static_url_path
    
            if self.static_folder is not None:
                return '/' + os.path.basename(self.static_folder)
    
        def _set_static_url_path(self, value):
            self._static_url_path = value
    
        static_url_path = property(
            _get_static_url_path, _set_static_url_path,
            doc='The URL prefix that the static route will be registered for.'
        )
        del _get_static_url_path, _set_static_url_path
    
        @property
        def has_static_folder(self):
            """This is ``True`` if the package bound object's container has a
            folder for static files.
    
            .. versionadded:: 0.5
            """
            return self.static_folder is not None
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 爻灵 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    网站公告
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部