1

I am working through the basic Blog tutorial on Django and After creating an app I have to add it to the veiw, What I don't understand is what the render functions' argument CONTEXT is for, and why are we using a dictionary.

I have already been through the official documentation but I couldn't understand it.

Here's what I am doing.

    render(request,'users/register.html', { 'form': form})
obadul024
  • 163
  • 1
  • 1
  • 13
  • 1
    As an aside, I wanted to give you some advice that I give to people who are working on tutorials. It might seem counter-intuitive, but tutorials generally are not like university classes where you need to fully understand everything before continuing on to the next section. It is best to do the entire tutorial (even when things seem fuzzy) because by the end you'll have used many concepts (including template context) so often that you will develop an understanding over time. – Greg Schmit Apr 04 '19 at 21:26
  • I will certainly do what you mentioned. But this kept bugging me alot, so I had to ask. thanks a ton – obadul024 Apr 04 '19 at 21:30

2 Answers2

4

It supplies the variables to display in the template.

For example, if your template had this bit of html:

<p>Hello {% first_name %}.</p>

And if you pass the first_name variable in the context:

render(request,'users/register.html', {'form': form, 'first_name': 'John'})

The template would display Hello John.

John Gordon
  • 29,573
  • 7
  • 33
  • 58
-2

What you provide in context argument is available in the template. So in your example, you can access form in your html templates.

Ozgur Akcali
  • 5,264
  • 2
  • 31
  • 49