Chez ouam

/home/jmfrouin

View on GitHub
12 June 2013

Django 1.6.5 sur Ubuntu

by Jean-Michel Frouin

Ce mémo vise à détailler l'installation de Django 1.6.5 sur Ubuntu au lieu de la version qui est dans les dépôts.
Et à centraliser les informations importante sur Django.

Prérequis

Par défaut il vous faut python, installé par défaut sur ubuntu, sinon :

sudo apt-get install python

Vérification de la version de python :

python
Python 2.7.4 (default, Apr 19 2013, 18:28:01)

On récupère PIP :

curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py

Et on l'installe :

sudo python get-pip.py

Il se peut que l'on est pas setuptools :

An error occured while trying to run get-pip.py. 
Make sure you have setuptools or distribute installed.

Du coup on l'installe :

sudo apt-get install python-setuptools

Django

Maintenant on installe Django :

sudo pip install Django==1.6.5

Vérification de la version de Django :

python -c "import django; print(django.get_version())"
1.6.5

Création d'un projet

Création initiale d'un projet :

django-admin.py startproject nom_projet

Directement, donnons les droits d’exécution à manage.py :

chmod +x manage.py

Lancer le serveur

./manage.py runserver

Et voilà, le projet est accessible depuis http://127.0.0.1:8000/
On peut simplement changer le port ainsi :

./manage.py runserver port

Configuration de la BDD

La configuration se fait dans le fichier settings.py.

Installons le support de MySQL pour Python :

sudo apt-get install python-mysqldb

Et enfin créons les schémas dans la base SQL :

./manage.py syncdb

Créons une application

./manage.py startapp mon_app

Savoir où est installé Django

python -c "
import sys
sys.path = sys.path[1:]
import django
print(django.__path__)"

Démarer un projet

./manage.py startproject projet

Démarer une application

./manage.py startpapp application

Documentation

init.d script for Linux
Django Admin
Django Settings
URLs dispatcher
Deployement with WSGI
Templates
<a href="https://docs.djangoproject.com/en/1.5/ref/models/fields/#field-types" target"=_blank">Fields type</a>
Django Snippets
Champs pour formulaire

Références

Installing official Django release
Quick Install Guide

tags: