2.3.1 Webpage Data

Webpage data are typically stored in the views.py file of any app. This may seem confusing, given the Model-View-Controller architecture. For the moment, remember that Django views and MVC Views are unrelated concepts!

Open the file found at /helloworld/views.py. Erase the contents of the file and replace them with the code shown in Example 2.3.

Example 2.3: Project Code

helloworld/views.py in 9937ef66c0

1  from django.http import HttpResponse 2 3 4  def greeting(request): 5      return HttpResponse('Hello World!')

Our webpage is simply a Python function called greeting(). Given our understanding of HTTP request/response, we can already see how Django handles this for us. Django gives our function ...

Get Django Unleashed 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.