Aller au contenu

Installer Django

Django est un framework Web Python.

Installer mysqlclient

$ pip3 install mysqlclient

Installer Django

$ pip3 install Django

$ python3 -m django --version
2.0.2

Django avec Apache et mod_wsgi

Se positionner en dehors de Document root (/Users/bruno) pour démarrer un projet Django:

~$ django-admin startproject mydjango

Installer mod_wsgi depuis pip:

$ APXS=/usr/local/bin/apxs pip3 install mod_wsgi

ou depuis Homebrew:

$ brew uninstall -vd mod_wsgi
$ brew install -vd mod_wsgi --with-homebrew-python

Lancer la commande mod_wsgi-express module-config pour connaitre les directives à ajouter à la configuration d'Apache (httpd.conf):

$ mod_wsgi-express module-config
LoadModule wsgi_module "/usr/local/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-darwin.so"
WSGIPythonHome "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6"

Une fois https.conf modifié, relancer Apache:

$ sudo apachectl -k restart -e Debug -E /dev/stdout

Une autre option est de copier le module mod_wsgi dans l'installation d'Apache avec la commande mod_wsgi-expressinstall-module

Se positionner dans le dossier mydjango pour démarrer le serveur:

$ python3 manage.py runserver

Pour changer le port (8000 par défaut)

$ python3 manage.py runserver 8001

Créer les tables dans la BDD.

$ python3 manage.py migrate

Création d'un utilisateur administrateur.

$ python manage.py createsuperuser

https://docs.djangoproject.com/fr/2.0/intro/tutorial03/#write-views-that-actually-do-something


Dernière mise à jour: November 9, 2023