Django – Hello World
Pre-requisites:
Hello World project in <dev root>/Projects/HelloWorldDjango
- Switch to <dev root>/Projects
- django-admin.py startproject HelloWordDjango (create the basic project files)
- cd HelloWorldDjango
- Check if it works so far: python manage.py runserver (start the test server)
- Ctrl-C to stop the test server
- Create the view: In <dev root>/Projects/HelloWorldDjango/HelloWorldDjango, create a file called “views.py” with the following content:
from django.http import HttpResponsedef hello(request):
return HttpResponse(“Hello world”) - Set the URL:
- In <dev root>/Projects/HelloWorldDjango/HelloWorldDjango/urls.py, add the following to the import line:
from HelloWorldDjango.views import hello - In the same file, add the following to the urlpatters list:
(‘^hello$’, hello),
- In <dev root>/Projects/HelloWorldDjango/HelloWorldDjango/urls.py, add the following to the import line:
- Start the test server: in <dev root>/Projects/HelloWorldDjango, python manage.py runserver
- In your browser go to http://localhost:8000/hello. This should show you “Hello world”