Django views – time to create!

    A view is a place where we put the “logic” of our application. It will request information from the you created before and pass it to a template. We’ll create a template in the next chapter. Views are just Python functions that are a little bit more complicated than the ones we wrote in the Introduction to Python chapter.

    Views are placed in the views.py file. We will add our views to the blog/views.py file.

    OK, let’s open up this file and see what’s in there:

    {% filename %}blog/views.py{% endfilename %}

    Remember that lines starting with are comments – this means that those lines won’t be run by Python.

    Let’s create a view as the comment suggests. Add the following minimal view below it:

    {% filename %}blog/views.py{% endfilename %}

      As you can see, we created a function (def) called that takes request and return a function render that will render (put together) our template .

      Another error! Read what’s going on now:

      This shows that the server is running again, at least, but it still doesn’t look right, does it? Don’t worry, it’s just an error page, nothing to be scared of! Just like the error messages in the console, these are actually pretty useful. You can read that the TemplateDoesNotExist. Let’s fix this bug and create a template in the next chapter!