This is a tutorial like the Symfony2 tutorial to demonstrate a simple Django CRUD-like web app. The particularity is the usage of SQLAlchemy for ORM, instead of the ORM provided by Django. SQLAlchemy is a data mapper ORM like Doctrine2 in PHP or Hibernate in java and it's very powerful. So it's best comparable to my PHP tutorial.
First, we need some system packages to let SQLAlchemy speak with MySQL:
sudo apt-get install libmysqlclient-dev python-dev
We will install the project in a virtual environment, the recommended way to deal with python projects. So first install these tools if you don't have it:
sudo apt-get install python-setuptools
sudo easy_install pip
pip install virtualenv
Then create the virtual environment for you project like this:
virtualenv /home/foo/django-tutorial
This creates the /home/foo/django-tutorial directory with some files to create an isolated python environement.
Now activate the environment and we're ready to go!
source /home/foo/django-tutorial/bin/activate
The prompt will now display (django-tutorial) to indicate we are into the virtual environment. To quit it and go back to normal shell, just type:
deactivate
Time to install the framework and libs our project will use:
pip install django
pip install sqlalchemy
pip install mysql-python
Follow these steps to start from scratch, otherwise the git repository contains everything needed.
django-admin.py startproject projet_test
It creates a little tree with some python files in it, mainly manage.py which is the central point to manage the django project.
Then you need to create a django app that we name here albums:
cd projet_test
python manage.py startapp albums
Final step to launch our web app:
python manage.py runserver
Now your web app is accessible through url: http://localhost:8000/ To run this example, use the url: http://localhost:8000/albums