'function' object has no attribute 'as_view' 'function' object has no attribute 'as_view' python python

'function' object has no attribute 'as_view'


IngredientCreateView should be a class.So your views.py replace:

def IngredientCreateView(CreateView):

with:

class IngredientCreateView(CreateView):


In my case, the problem was that I tried to use a @decorator on the class-based view as if it was a function-based view, instead of @decorating the class correctly.

EDIT: From the linked page, here is a way to apply @login_required to a class-based view:

from django.contrib.auth.decorators import login_requiredfrom django.utils.decorators import method_decorator@method_decorator(login_required, name='dispatch')class ProtectedView(TemplateView):


IngredientCreateView is a function, not a class.

The following line

def IngredientCreateView(CreateView):

should be replace with

class IngredientCreateView(CreateView):