Django Rest Framework: 'function' object has no attribute 'as_view'

后端 未结 5 1075
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-30 01:34

I\'ve been trying for a while to get a ModelResource or a View working using the Django Rest Framework. I\'m following the examples but the code in the examples is not worki

5条回答
  •  天涯浪人
    2020-12-30 02:04

    I am also getting this error but in my case i solved it with following idea.

    That error usually happens if you try to override a class. That sometimes happens if you copy&paste code and forget to change e.g. the class name. But in my case it was little different

    If you apply @login_required to a class, you will receive the error message:

    ‘function’ object has no attribute ‘as_view’

    So, how should you decorate classes in Django now? For class-based views, you have two options of decorating your classes.

    1) Decorating the URLconf

    2) Decorating the class

    Both options leads to the same result - restricting the access to a class only for logged users. The difference between the options is how the decorator is applied to the class instance.Refer this page for decorators implementation

    https://docs.djangoproject.com/en/1.4/topics/class-based-views/#decorating-class-based-views

提交回复
热议问题