The website of the Django web framework can be found on https://www.djangoproject.com/.
Installation
The current version of Django (2011-06-13: v1.3) can be installed on Ubuntu/Debian using
sudo apt-get install python-setuptools
sudo easy_install django
(The install-dir on Ubuntu 11.04 will be /usr/local/lib/python2.7/dist-packages. More on the install-dir can be read in a blog post by jeremy.)
An outdated version of Django can be found in the Ubuntu and Debian package management:
sudo apt-get install python-django
check version:
$ python
>>> import django
>>> django.VERSION
(1, 0, 'final')
Create a Django Project
http://www.djangobook.com/en/2.0/chapter02/
Start a Project
In general:
django-admin.py startproject django_bookmarks
If you installed Django via the Ubuntu/Debian package the command django-admin.py above should read django-admin .
Set your Settings: set up admin-user, enable the admin module and specify a database
Change file settings.py (to use sqlite3):
vi django_bookmarks/settings.py
and enter:
ADMINS = (
('Your Name', 'your.name@example.com')
)
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'bookmarksdb'
TIME_ZONE = 'Europe/Berlin'
LANGUAGE_CODE = 'en-GB'
INSTALLED_APPS = (
'django.contrib.admin',
[...]
)
Now you are able to create the database and create the basic tables for django:
cd django_bookmarks
python manage.py syncdb
python manage.py createsuperuser
Create an application inside the project
This will create the application bookmarks:
python manage.py startapp app
Now you’ve got the directory “app” with the files init.py, views.py and models.py.
You are ready now to create an HTML template:
cd django_bookmarks
mkdir templates
Adjust the URLs
Uncomment the following lines in django_bookmarks/urls.py:
from django.contrib import admin
admin.autodiscover()
url(r'^admin/', include(admin.site.urls)),
No run (or rather debug) the project via
cd django_bookmarks
python manage.py runserver
You can then go to http://localhost:8000/ and http://localhost:8000/admin to see the result.
This was your first start into Django. The next steps are to add some models and views (including their URLs and templates). See these posts for more information:
Resources
- Documentation overview: http://docs.djangoproject.com/en/dev/contents/
- HowTo to get started (good!): http://docs.djangoproject.com/en/dev/intro/
- see Linux Magazin 4/2009 p104:
http://www.linux-magazin.de/online_artikel/reloaded_django_video_workshop_von_douglas_napoleone?category=0 - Good Django Applications
- Good Examples can be found
- on http://code.djangoproject.com/wiki/DjangoResources#Djangoapplicationcomponents
- and on: http://www.djangopackages.com/
- and here are sites powered by Django: http://www.djangosites.org/
- specific example projects:
- django robots: manage robots.txt using a Django interface: https://github.com/jezdez/django-robots/