99 lines
2.0 KiB
Markdown
99 lines
2.0 KiB
Markdown
# Installer Django
|
|
|
|
|
|
|
|
[Django](https://docs.djangoproject.com/en/2.0/topics/install/#installing-distribution-package) est un framework Web Python.
|
|
|
|
|
|
|
|
#### Installer [mysqlclient](https://pypi.python.org/pypi/mysqlclient)
|
|
|
|
```bash
|
|
$ pip3 install mysqlclient
|
|
```
|
|
|
|
|
|
|
|
#### Installer Django
|
|
|
|
```bash
|
|
$ pip3 install Django
|
|
|
|
$ python3 -m django --version
|
|
2.0.2
|
|
```
|
|
|
|
[Django avec Apache et mod_wsgi](https://docs.djangoproject.com/fr/2.0/howto/deployment/wsgi/modwsgi/)
|
|
|
|
|
|
|
|
Se positionner en dehors de <u>Document root</u> (/Users/bruno) pour <u>démarrer un projet Django</u>:
|
|
|
|
```bash
|
|
~$ django-admin startproject mydjango
|
|
```
|
|
|
|
|
|
|
|
Installer [mod_wsgi](https://pypi.python.org/pypi/mod_wsgi) depuis <u>pip</u>:
|
|
|
|
```bash
|
|
$ APXS=/usr/local/bin/apxs pip3 install mod_wsgi
|
|
```
|
|
|
|
ou depuis Homebrew:
|
|
|
|
```bash
|
|
$ 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):
|
|
|
|
```bash
|
|
$ 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 <u>https.conf</u> modifié, relancer Apache:
|
|
|
|
```bash
|
|
$ sudo apachectl -k restart -e Debug -E /dev/stdout
|
|
```
|
|
|
|
Une autre option est de copier le module <u>mod_wsgi</u> dans l'installation d'Apache avec la commande `mod_wsgi-expressinstall-module`
|
|
|
|
|
|
|
|
Se positionner dans le dossier <u>mydjango</u> pour démarrer le serveur:
|
|
|
|
```bash
|
|
$ python3 manage.py runserver
|
|
```
|
|
|
|
Pour changer le port (8000 par défaut)
|
|
|
|
```bash
|
|
$ python3 manage.py runserver 8001
|
|
```
|
|
|
|
|
|
|
|
Créer les tables dans la BDD.
|
|
|
|
```bash
|
|
$ python3 manage.py migrate
|
|
```
|
|
|
|
Création d'un utilisateur administrateur.
|
|
|
|
```bash
|
|
$ python manage.py createsuperuser
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
https://docs.djangoproject.com/fr/2.0/intro/tutorial03/#write-views-that-actually-do-something |