60
IngredientCreateView
should be a class.
So your views.py replace:
def IngredientCreateView(CreateView):
with:
class IngredientCreateView(CreateView):
62
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_required
from django.utils.decorators import method_decorator
@method_decorator(login_required, name='dispatch')
class ProtectedView(TemplateView):
- [Django]-How to get a list of all users with a specific permission group in Django
- [Django]-Celery: When should you choose Redis as a message broker over RabbitMQ?
- [Django]-Django: add image in an ImageField from image url
10
IngredientCreateView
is a function, not a class.
The following line
def IngredientCreateView(CreateView):
should be replace with
class IngredientCreateView(CreateView):
- [Django]-Django excluding one queryset from another
- [Django]-Difference between auto_now and auto_now_add
- [Django]-How to configure where to redirect after a log out in Django?
4
def Some_def_View(CreateView):
#should be replaced with
class SomeClassView(CreateView)
- [Django]-How to strip html/javascript from text input in django
- [Django]-Naming convention for Django URL, templates, models and views
- [Django]-Django Admin: OneToOne Relation as an Inline?
2
In addition to what is already said here, Check the file name and class name if it is same then you might have to import the class properly.
File name /api/A.py
class A:
//some methods
In your main class
//App main class
from api.A import A
- [Django]-Form field description in django admin
- [Django]-How to format dateTime in django template?
- [Django]-Django Broken pipe in Debug mode
2
I faced the same problem but this solution worked for me..
in views.py file in viewclass you can use viewsets instead of CreateView
from rest_framework import viewsets
class YourClassView(viewsets.ModelViewSet):
in urls.py file you can use this routing pattern
from django.conf.urls import url
from rest_framework import routers
router = routers.DefaultRouter()
router.register('books',YourClassView)
urlpatterns = [
path('', include(router.urls)),
path('admin/', admin.site.urls)
]
- [Django]-Django – How to use decorator in class-based view methods?
- [Django]-Django URL Redirect
- [Django]-How to handle request.GET with multiple variables for the same parameter in Django