A super-minimal Django "hello world" example repo.
Python
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
mysite
.gitignore
README.md

README.md

hello-django

The minimum "hello world" for Django 1.4. Views only, no code having anything to do with model/database/etc.

Assumes Django 1.4+ is installed (pip install django or easy_install django). See "Notes" section below.

Running "Hello World"

From inside the repo root:

cd mysite
python manage.py runserver

Then open http://127.0.0.1:8000/ .

How this repo was put together

These are the commands that were run to create this repo (once I was cd'd into the root of this repo):

django-admin.py startproject mysite
cd mysite
python manage.py startapp myapp

These steps basically define:

  1. a mysite directory that contains a bunch of Django boilerplate which (essentially) defines the "website" you are starting to build.
  2. a myapp directory inside mysite, containing (empty) boilerplate files that define a yet-to-be-worked-on Django app. Django projects are split up into "apps", that can all define their own database table models, URLs, and views. (i.e. on a news website, you could define different apps for articles, staff, and photos and work on those sections and features separately)

The result of these "boilerplate generation" steps comprised the first code commit.


Then mysite/myapp/views.py was edited to contain the little bit of code you see inside that file now.

mysite/mysite/urls.py was edited to add the following line inside the patterns('', ...) bit.

url(r'^$', 'myapp.views.hello'),

These steps comprised the next commit. (See also comment on that commit.)

That's it.

Notes

This doesn't use virtualenv or any other "best practices" things to contain the Django installation. This doesn't explain anything other than how to get plain Python code spitting out an HttpResponse that says "Hello, world" at the / URL.


What now?

You should read the official Django tutorial to start learning more about the structure of a Django app and how to use Django's ORM to work with a database.

The Django Book is technically outdated (originally written for Django 1.0, in 2009), but the first handful of chapters are a great resource for those learning the ropes.

Once you get your land legs, the official Django documentation is a great reference to keep on-hand.

If you're new to Python (and even if you're not), the Python documentation is equally useful and well-structured in terms of the API. (i.e.: Need to know about the datetime module and see examples of it's functions in use? The datetime documentation has you covered.)