Your second view: dynamic content

Our Hello World view was instructive in demonstrating the basics of how Django works, but it wasn't an example of a dynamic web page, because the content of the page is always the same. Every time you view /hello/, you'll see the same thing; it might as well be a static HTML file.

For our second view, let's create something more dynamic-a web page that displays the current date and time. This is a nice, simple next step, because it doesn't involve a database or any user input-just the output of your server's internal clock. It's only marginally more exciting than Hello World, but it'll demonstrate a few new concepts. This view needs to do two things: calculate the current date and time, and return an HttpResponse ...

Get Mastering Django: Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.