2013年9月21日星期六

Crusher Django Tutorial(1) hello world

Hello,everyone,I will start a Django Tutorial,and I
am a big Fan of Python and Django,So, I mean I am
crush into Python and Django.
I using the GNU/Linux Operating System to
learning the Python and Django, and I think the
Windows CMD is too weak to doing the
Programming. :) Let us start the tutorial with the
Terminal in the Linux.
Let us try hello world with the terminal.

Then we install the Django(the install is so easy ,
and I skip the step).
First,we check out the django lib is ok in your
system:

Well,well,well, the django is installed in your
System.
Then we can just turn a directory that is English
path(I am a Chinese),so maybe there is nothing not
prefect with you.
Here I use the root directory of my user ~ :

zoo@ubuntu:~$ django-admin startproject hello

nothing error, nothing means everything ok.
And check the path, there is a folder Added named
hello. All right, that is our base directory.

In the folder, there are four files

the __init__.py is a file that will make the folder as a
packet as default.I do not know the more about it.
LOL...
the manage.py includes the all kinds of the
command we can use.

The settings.py is all kinds of the setting of the
project,like the database we use, the templates we
set down and so on, we will talk about it later.

The url.py is all the url Configuration we use it to
conf the views to the function.If you do not
understand, just do it, the more you do, the more
you will understand.

Ok, just start the “hello world” page!
Just open the terminal and start the command:

the runserver means start the server, use django
you won't have to use the server like Apache or
Nignx,just django!BTW, the 0.0.0.0 means if you
have a public IP Address, your friends not in your
local network will see your page, that is real cool!
Now you can open the Chrome or firefix and type
the address:

the line of :
from views import *
means import the function to the current file:url.py
the line :
(r'^$', hello),
means the bind nothing of the url to the
function.That means you refresh the
http://localhost:8000
you can see the webpage we created:

Now, we create the first django page, in fact we can make the page a little
more complex:
just add the html like this in the “”””””: