(regex, name=None, methods=None, bind=False)
return decorator
函数view装饰器,方便生成非class-based View
函数view装饰器,方便生成非class-based View
函数view装饰器 方便生成非class - based View
def wechat_view(regex, name=None, methods=None, bind=False):
    """函数view装饰器,方便生成非class-based View"""

    methods = methods or ("GET",)

    def decorator(func):
        """
        :rtype: wechat_django.sites.wechat.WeChatView
        """
        @wraps(func)
        def view(self, request, *args, **kwargs):
            return func(request, *args, **kwargs)

        attrs = {method.lower(): func if bind else view for method in methods}
        attrs["url_pattern"] = regex
        attrs["url_name"] = name
        return type(str("WeChatView"), (WeChatView,), attrs)

    return decorator
def wechat_view ( regex , name = None , methods = None , bind = False ) : methods = methods or ( "GET" , ) def decorator ( func ) : """
        :rtype: wechat_django.sites.wechat.WeChatView
        """ @ wraps ( func ) def view ( self , request , * args , * * kwargs ) : return func ( request , * args , * * kwargs ) attrs = { method . lower ( ) : func if bind else view for method in methods } attrs [ "url_pattern" ] = regex attrs [ "url_name" ] = name return type ( str ( "WeChatView" ) , ( WeChatView , ) , attrs ) return decorator