[Answered ]-How to display extra context and form fields at the same time on django template using class based view?

1👍

get_context_data is a method on the parent class. If you override it, you still need to call the parent method which is what adds the form to the context. You do this by calling super() inside your own method, to obtain the context data, and then add your own:

def get_context_data(self, *args, **kwargs):
    context = super().get_context_data(*args, **kwargs)
    context['prb'] = Problem.objects.select_related()
    return context

Refer to the documentation on adding extra context to see how you should use get_context_data.

0👍

This worked for me in a similar scenario

def get_context_data(self, *args, **kwargs):
    context = super().get_context_data(**kwargs)
    prb = Problem.objects.select_related()
    context.update({'prb': prb})

    return context
👤Keybet

Leave a comment