基于django 开发的框架 jumpserver 源码解析(一) 基于类的视图,以及url 路由解析

基于类的视图,以及url 路由解析

  jumpserver 这个轮子是好跑的轮子,又大又圆,对源码进行解析。

 

jumpserver  中 用了 大量的基于类的视图函数,相对抽象一点,隐藏了一些细节。大量使用 类似下面的url路由。

urlpatterns = [
    url(r'^v1/assets-bulk/$', api.AssetListUpdateApi.as_view(), name='asset-bulk-update')]

跟 基于函数的视图不一样, 配置类视图的时候,需要使用类视图的as_view()方法来注册添加,

as_view 方法 是django 内置base 类中,view类的 类方法。下面贴出源码

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']

    def __init__(self, **kwargs):
        """
        Constructor. Called in the URLconf; can contain helpful extra
        keyword arguments, and other things.
        """
        # Go through keyword arguments, and either save their values to our
        # instance, o
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值