django class view问题

问题:在通用类视图类的A方法中动态添加一个属性,如self.username,在B方法中访问该属性却报属性错误,推断是通用视图类会不停地创建和销毁。查询django文档如下,可知的确是每次url在分配view的时候都会创建不同的对象。通过日志输出,如下图,也证明对象的确不同。


Because Django’s URL resolver expects to send the request and associated arguments to a callable function, not a class, class-based views have an as_view() class method which serves as the callable entry point to your class. The as_view entry point creates an instance of your class and calls its dispatch() method. dispatch looks at the request to determine whether it is a GETPOST, etc, and relays the request to a matching method if one is defined, or raises HttpResponseNotAllowed if not:


142103_li6D_2348771.png

转载于:https://my.oschina.net/u/2348771/blog/410824

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值