> sudo apt-get install python-django
> django-admin startproject sampleproject
Then, directory sampleproject is created.
You can run test server using manage.py in the directory.
You can set details using setting.py.
You can set urls using urls.py
Setting DB(ex. SQLite)
- Set DATABASE_NAME, DATABASE_ENGINE
Then create DB.
> ./manage.py syncdb
- Chose if you will set superuser account.
> ./manage.py runserver
Check it with url 'http://localhost:8000/'
(8000 is default.)
In one project, you can have several web-applications. Django calls it as applications.
Create with commands,
> ./manage.py startapp sampleapp
Directory sampleapp is then generated.
Application is recommended to be designed with MVC model.
In sampleapp directory,
You can define http request handler function in the file views.py
from django.http import HttpResponse
output = "<html>Welcome!</html>"
'request' has many informations about current requests.
from sampleapp.views import *
urlpatterns = patterns('',
In 'r'^$', r means regular expression, ^ is first of uri and $ stands for the last.
So it means '/' actually. Function main has been set as a handler for '/' above.
Now, check your first page with browser using 'http://localhost:8000/'. Good job!
You can use expressions like below
. ^ $ * + ? | [a-z] \w \d
\w means alphabet or '_'
\d means one letter digit.