As you can see, its a very simple view, merely passing a generated
number to the render_to_response function we created before.

Next, we need to create our index.html template that
the index view is trying to render. To do that, first
we are going to create a base.html template in the
loose_coupling/templates directory. So, open up
loose_coupling/templates/base.html and add this
to it

And now we need to create the
loose_coupling/with_jinja/templates/with_jinja/index.html template.
It will extend our base template and be quite simple:

{%extends'base.html'%}{%blockcontent%}<p> The number generated was {{n}}. </p>{%ifnisgtf%}<p> The number was definitely greater than fifty.</p>{%else%}<p> Unfortunately, the number was below fifty.</p>{%endif%}{%endblock%}

Now, save all the files and run the project.

python manage.py runserver

Now navigate over to http://127.0.0.1:8000
and you'll see Django development server merrily rendering our Jinja2
template.

Thanks to Django's loose coupling philosophy, it was really quite painless
to switch over to using Jinja2 instead of the default templating language.
As this series continues we'll look at how this isn't just a freak
occurance, but occurs throughout the Django stack.

Hi folks. I'm Will, known as @lethain on Twitter.
I write about software and management topics,
and love email at lethain[at]gmail.
Get email from me by subscribing to
my weekly newsletter.