Reputation: 21
I am trying to make a custom mixin for my Carousel but I am getting this error File "/src/content/urls.py", line 3, in from . import views File "/src/content/views.py", line 34, in class IndexView(CarouselObjectMixin, ListView): NameError: name 'CarouselObjectMixin' is not defined the mixin that I made was added to my content app
class IndexView(CarouselObjectMixin, ListView):
model = Post
template_name = 'index.html'
cats = Category.objects.all()
ordering = ['-post_date']
ordering = ['-id']
def get_context_data(self, *args, **kwargs):
cat_menu = Category.objects.all()
context = super(IndexView, self).get_context_data(*args, **kwargs)
context["cat_menu"] = cat_menu
return context
but the custom mixin is in my slideshow app.
Function Based View
views.py
def SlideShowView(request):
carousel = Carousel.objects.all()
context = {
'carousel' : carousel,
}
return render(request, "showcase.html", context)
Converted to Class Based View
views.py
class SlideShowView(ListView):
model = Carousel
context_object_name = 'carousel'
template_name = 'showcase.html'
Custom Mixin
views.py
class CarouselObjectMixin(object):
model = Carousel
context_object_name = 'carousel'
template_name = 'showcase.html'
Upvotes: 0
Views: 47
Reputation: 5600
From the error message it seem like CarouselObjectMixin
is not imported in src/content/views.py
file
Upvotes: 1