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
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
into the root of this repo):
django-admin.py startproject mysite cd mysite python manage.py startapp myapp
These steps basically define:
mysitedirectory that contains a bunch of Django boilerplate which (essentially) defines the "website" you are starting to build.
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
photosand work on those sections and features separately)
The result of these "boilerplate generation" steps comprised the first code commit.
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.
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
HttpResponse that says "Hello, world" at the / URL.
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.)