In the previous video, we already learned about templates in Django. Now in this video, 2
we are going to learn about context. Context mean that we can pass data from our 3
views.py file to templates file. 4
Okay let’s open the visual studio code and I will show you what i mean 5
Go to views.py inside app1 directory 6
Let me explain about context first. In simple word, the purpose of context is that we can 7
access the variable that we have defined in the views.py from the template file. 8
Let’s create a context in hello world function, the type of context must be a dictionary 9
in this example I create a dictionary about me, the name will be Ahmad 10
and let’s say the age is 21. Now we need to pass this context in the return statement. 11
When we pass a context in return statement like this, we can access this data from the 12
templates, let’s open hello world.html, here I can access the context data in templates 13
file using double curly braces like this. Let’s also put a age context here. 14
Now let’s open the browser and go to app1/hello_world, Here we can see that we get Ahmad and 21. 15
Okay I think this is enough for this video. Hope you guys understand about context in Django 16
Thank you for watching and see you on the next video