May 2018
Beginner to intermediate
526 pages
11h 57m
English
Let's create a context processor to set the current cart into the request context. We will be able to access the cart in any template.
Create a new file inside the cart application directory and name it context_processors.py. Context processors can reside anywhere in your code, but creating them here will keep your code well organized. Add the following code to the file:
from .cart import Cartdef cart(request): return {'cart': Cart(request)}
A context processor is a function that receives the request object as a parameter and returns a dictionary of objects that will be available to all the templates rendered using RequestContext. In our context processor, we instantiate the cart using the request ...
Read now
Unlock full access