I'm setting up my layout in Django using functional views but decide to change it out for classes. I'm a bit lost as to how I can get the information from the views into my template however.
My first attempt was below
class Menu(generic.ListView):
model = Categories
template_name = 'portfolio/layout.html'
context_object_name = 'category_list'
# def get_queryset(self):
# return Categories.objects.all()
class IndexView(Menu):
template_name = 'portfolio/index.html'
This allowed me to set up layout.html with my menu items by iterating through "category_list". The menu items carried over in index.html that extended layout.html
After doing a bit more research, I decided to set up my views as follows:
class MenuView(object):
def get_context_data(self, *args, **kwargs):
context = super(MenuView, self).get_context_data(*args, **kwargs)
context['menu'] = Categories.objects.all()
return context
class LayoutView(generic.TemplateView):
template_name = 'portfolio/layout.html'
I'm still getting my head around how this works, but according to this tutorial (https://blog.safaribooksonline.com/2013/10/28/class-based-views-in-django/) I think I am updating the get_context_data function to include my query for the Categories model. I can't figure out how to access context['menu'] to display into my template however.