i want to call class based index view in function view i render the index template in login function view but when i add a extra context in index template which i do from function views ' it only render's extra context not the one which is already rendered by class based index view.
so i thought if i could call class based index view from function so that i add extra context to class based view and render it at the same time.
in short word's i want to add extra context from function view and render it.
this is my class based generic view for listing object's in index template.
class IndexView(generic.ListView):
template_name = 'polls/index.html'
title = 'hello'
num_visit = 'a'
context_object_name = 'question_list'
def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.filter(pub_date__lte=timezone.now()).order_by('-pub_date')[:5]
and this is my login view that render's the same template which class based index view does
def login_view(request):
user = authenticate(request,username=request.POST['username'],password=request.POST['password'])
if user is not None:
login(request, user)
return redirect('polls:index')
return render_to_response('polls/index.html', {'error_message': 'wrong credentials'})
.................................................
now i can login in index template but the look at the code context adding does'nt workin maybe it work's but i think it does messes up with default object list context.
class IndexView(generic.ListView):
template_name = 'polls/index.html'
title = 'sdasd'
num_visit = 'a'
context_object_name = 'question_list'
error_message = None
def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.filter(pub_date__lte=timezone.now()).order_by('-pub_date')[:5]
def post(self, request, **kwargs):
user = authenticate(request, username=request.POST['username'], password=request.POST['password'])
if user is not None:
login(request, user)
return redirect('polls:index')
error_message = 'i love jesus'
context = self.get_context_data(request, error_message, **kwargs)
return render(request, 'polls:index', context)
def get_context_data(self, *args, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
context['error_message'] = self.args
return context
Template code .............. cant add the template code ' it's complicated i added here https://codeshare.io/5zXYJb
trackback error https://ibb.co/jdA7Ek