Your first Django-powered page: Hello World
As our first goal, let's create a web page that outputs that famous example message: Hello World. If you were publishing a simple Hello World web page without a web framework, you'd simply type Hello world
into a text file, call it hello.html
, and upload it to a directory on a web server somewhere. Notice in that process you've specified two key pieces of information about that web page: its contents (the string Hello world
) and its URL (for example, http://www.example.com/hello.html
). With Django, you specify those same two things, but in a different way. The contents of the page are produced by a view function, and the URL is specified in a URLconf. First, let's write our Hello World view function.
Your first view
Within the mysite
directory that we created in the last chapter, create an empty file called views.py
. This Python module will contain our views for this chapter. Our Hello World view is simple. Here's the entire function, plus import...