Reputation: 46979
In the following code i am trying to call Homeviews
class inside HomeView
function which inturn is called by urls.py. But i do not see get_context_data
being called. but if i separate class of HomeViews
independently then i can see that get_context_data
is being called and arguments are called explicitly. From the following code how can i implement the functionality
views.py
def HomeView(request):
print "Inside def====1"
class HomeViews(TemplateView):
def __init__(self):
print "Inside class====2"
def get_context_data(self, **kwargs):
print "Infunc====3"
hv = HomeViews.as_view()
print "After calling class"
return HttpResponseRedirect("/someurl")
urls.py
url(r'^$', login_required(views.HomeView), name='home'),
Upvotes: 0
Views: 156
Reputation: 118548
I'm not going to ask why you're doing this, but to do so, pass the view into the hv
view function you just generated.
def some_view(request):
view = generic.TemplateView.as_view(template_name='foobar')
return view(request)
or
hv = HomeViews.as_view()
response = hv(request)
Upvotes: 1