Answer the question
In order to leave comments, you need to log in
How to write controller code shorter in such a case?
When passing the context to the templates, I always pass the Basket - so that the header contains the number of items in the basket.
Controllers code:
def view1(request):
return render(request, 'template1.html', {'cart': cart})
def view2(request):
return render(request, 'template2.html', {'cart': cart})
def view3(request):
return render(request, 'template3.html', {'cart': cart})
<p>Корзина <span>{{ cart.get_count }}</span></p>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question