Django – Hello World

Pre-requisites:

  1. easy_install, pip, virtualenv – getting ready for Django
  2. Installing Django

Hello World project in <dev root>/Projects/HelloWorldDjango

  1. Switch to <dev root>/Projects
  2. django-admin.py startproject HelloWordDjango (create the basic project files)
  3. cd HelloWorldDjango
  4. Check if it works so far: python manage.py runserver (start the test server)
  5. Ctrl-C to stop the test server
  6. Create the view: In <dev root>/Projects/HelloWorldDjango/HelloWorldDjango, create a file called “views.py” with the following content:
    from django.http import HttpResponse

    def hello(request):
    return HttpResponse(“Hello world”)

  7. Set the URL:
    1. In <dev root>/Projects/HelloWorldDjango/HelloWorldDjango/urls.py, add the following to the import line:
      from HelloWorldDjango.views import hello
    2. In the same file, add the following to the urlpatters list:
      (‘^hello$’, hello),
  8. Start the test server: in <dev root>/Projects/HelloWorldDjango, python manage.py runserver
  9. In your browser go to http://localhost:8000/hello. This should show you “Hello world”

You may also like...