Commit aaf67a4e authored by Bonnegent Sebastien's avatar Bonnegent Sebastien
Browse files

preparation de la nouvelle version

parent b495089f
Pipeline #8432 failed with stage
in 18 seconds
docs:
image: ubuntu:20.10
before_script:
- apt-get update && apt-get install -y bash pandoc
- make clean
script:
- make
artifacts:
expire_in: 7 days
paths:
- html
all: cours1.html cours2.html cours3.html cours4.html cours5.html cours6.html cours7.html
all: html/cours1.html html/cours2.html html/cours3.html html/cours4.html html/cours5.html html/cours6.html html/cours7.html
%.html: %.md
pandoc -s -t revealjs -V revealjs-url=./reveal.js -V theme=beige -o $@ $<
html/%.html: %.md
@# pandoc -s -t S5 -o $@ $<
pandoc -s -t revealjs -V revealjs-url=./reveal.js-3.9.2 -V theme=moon -o $@ $<
@# pandoc -s -t revealjs -V revealjs-url=./reveal.js-4.1.0/js/ -o $@ $<
themes:
pandoc -s -t revealjs -V revealjs-url=./reveal.js-3.9.2 -V theme=beige -o html/cours1.beige.html cours1.md
pandoc -s -t revealjs -V revealjs-url=./reveal.js-3.9.2 -V theme=black -o html/cours1.black.html cours1.md
pandoc -s -t revealjs -V revealjs-url=./reveal.js-3.9.2 -V theme=blood -o html/cours1.blood.html cours1.md
pandoc -s -t revealjs -V revealjs-url=./reveal.js-3.9.2 -V theme=league -o html/cours1.league.html cours1.md
pandoc -s -t revealjs -V revealjs-url=./reveal.js-3.9.2 -V theme=moon -o html/cours1.moon.html cours1.md
pandoc -s -t revealjs -V revealjs-url=./reveal.js-3.9.2 -V theme=night -o html/cours1.night.html cours1.md
pandoc -s -t revealjs -V revealjs-url=./reveal.js-3.9.2 -V theme=serif -o html/cours1.serif.html cours1.md
pandoc -s -t revealjs -V revealjs-url=./reveal.js-3.9.2 -V theme=simple -o html/cours1.simple.html cours1.md
pandoc -s -t revealjs -V revealjs-url=./reveal.js-3.9.2 -V theme=sky -o html/cours1.sky.html cours1.md
pandoc -s -t revealjs -V revealjs-url=./reveal.js-3.9.2 -V theme=solarized -o html/cours1.solarized.html cours1.md
pandoc -s -t revealjs -V revealjs-url=./reveal.js-3.9.2 -V theme=white -o html/cours1.white.html cours1.md
firefox html/cours1.*.html
clean:
rm -f html/cours?.html html/cours1.*.html
This diff is collapsed.
......@@ -3,8 +3,8 @@ author:
- Sébastien Bonnegent
title: Django par la pratique 1/7
---
# Django
# Django
## Qu'est ce que c'est ?
> The web framework for perfectionists with deadlines.[^dj]
......@@ -24,32 +24,96 @@ title: Django par la pratique 1/7
- ...
## Inconvénients
- ?
- ? :)
## Utilisé par
- disqus
- dropbox (storage)
- instagram
- mozilla
- open stack
- pinterest
- spotify
- youtube
- ...
# Prérequis
- Disqus
- Instagram
- Mozilla
- Pinterest
- Spotify
- Youtube
Sources: [^gen] [^star]
[^gen]: \tiny https://docs.djangoproject.com/fr/3.1/faq/general/#is-django-stable
[^star]: \tiny https://djangostars.com/blog/10-popular-sites-made-on-django/
# Prérequis: python
## Système
### plus
- rapide
### moins
- pas la dernière version
- dépendant de la distribution (poste dév != production)
## pyenv
### plus
- rapide
- n'importe quelle version
- permet de gérer plusieurs versions
### moins
- plus compliqué pour la production (dépend de l'utilisateur)
## virtualenv
- virtualisation légère
- utilisation de pip
- `python3 -m venv env`
`source env/bin/activate`
`deactivate`
## docker
https://hub.docker.com/_/python/
https://docs.docker.com/compose/django/
### plus
- indépendance du système
- n'importe quelle version
- déploiement facile via docker-compose
### moins
- nécessite des droits root (ou équivalent)
- légèrement moins rapide
## podman
https://podman.io/
### plus
- indépendance du système
- n'importe quelle version
- pas de droit root
### moins
- mise en production (espace utilisateur)
- légèrement moins rapide
## Bibliothèques
### pip
- niveau système ou niveau utilisateur
- pas possible d'avoir plusieurs environnements
- gestion des dépendances (requirements.txt)
- `pip install -r requirements.txt`
### pipenv [^pipenv]
- utilise pip et virtualenv
- fichier Pipfile pour gérer les bibliothèques
- `pipenv install --dev`
- `pipenv run python ./manage.py`
## L'environnement pipenv[^pipenv]
[^pipenv]: https://gitlab.insa-rouen.fr/bonnegent/cours_django/wikis/pipenv
## Les supports
~~~
$ git clone https://gitlab.insa-rouen.fr/bonnegent/cours_django.git
$ cd cours_django
$ ls exemples
$ mkdir fwm1
$ cd !$
$ pipenv --python 3.6
$ pipenv install django django-extensions ipython
~~~
[^pipenv]: https://gitlab.insa-rouen.fr/bonnegent/cours_django/wikis/pipenv
https://gitlab.insa-rouen.fr/bonnegent/cours_django/-/blob/master/cours1.md
## Projet ou application ?
> Une application est une application Web qui fait
......@@ -61,18 +125,17 @@ $ pipenv install django django-extensions ipython
> plusieurs applications.
> Une application peut apparaître dans plusieurs projets.[^ted]
[^ted]: \tiny https://docs.djangoproject.com/fr/2.2/intro/tutorial01/
[^ted]: \tiny https://docs.djangoproject.com/fr/3.1/intro/tutorial01/
## Création du projet
~~~
$ pipenv run django-admin startproject conf .
$ django-admin startproject conf .
~~~
![](images/tree-conf.png)
## Création d'une application
~~~
$ pipenv run django-admin startapp webui
$ django-admin startapp webui
~~~
![](images/tree-webui.png)
......@@ -98,48 +161,48 @@ INSTALLED_APPS = [
DEBUG = True
ALLOWED_HOSTS = []
ROOT_URLCONF = 'conf.urls'
LANGUAGE_CODE = 'fr-fr'
LANGUAGE_CODE = 'fr'
TIME_ZONE = 'Europe/Paris'
SECRET_KEY = 'Une_clef_secrete_et_longue!'
~~~
### Pour générer une nouvelle clé secrête
~~~
$ pipenv run ./manage.py generate_secret_key
$ ./manage.py generate_secret_key
f#wgrz$@#wh@*x5)_+(*$$^aw(c!q#a4)c0230bwp!iy
~~~
## Gestion des migrations
### Création (si nécessaire)
~~~
$ pipenv run ./manage.py makemigrations
$ ./manage.py makemigrations
~~~
### Application
~~~
$ pipenv run ./manage.py migrate
$ ./manage.py migrate
~~~
![](images/tree-migrate-initial.png)
## Quelques commandes utiles
~~~
$ pipenv run ./manage.py shell
$ # shell avec chargement automatique des classes
$ pipenv run ./manage.py shell_plus
$ ./manage.py shell
$ # shell avec chargement automatique des modèles
$ ./manage.py shell_plus
~~~
~~~
$ pipenv run ./manage.py createsuperuser
$ ./manage.py createsuperuser
~~~
### Serveur de développement
~~~
$ pipenv run ./manage.py runserver
$ ./manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
September 28, 2017 - 13:29:48
Django version 1.11, using settings 'conf.settings'
November 02, 2020 - 22:37:51
Django version 3.1.3, using settings 'conf.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
~~~
......@@ -175,11 +238,11 @@ class Port(models.Model):
## Appliquer les modifications
~~~
$ pipenv run ./manage.py makemigrations
$ ./manage.py makemigrations
Migrations for 'webui':
webui/migrations/0001_initial.py
- Create model Port
$ pipenv run ./manage.py migrate
$ ./manage.py migrate
...
~~~
......@@ -209,7 +272,7 @@ class Migration(migrations.Migration):
~~~
## Shell django
### pipenv run ./manage.py shell
### ./manage.py shell
~~~python
>>> from webui.models import Port
>>> p = Port()
......@@ -241,7 +304,7 @@ class Port(models.Model):
~~~
## Shell plus
### pipenv run ./manage.py shell_plus
### ./manage.py shell_plus
~~~python
>>> p = Port(debut=80, protocole="tcp", fin=88)
>>> p
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
FROM python:3.8
ENV PYTHONUNBUFFERED=1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
......@@ -10,11 +10,12 @@ pytest-django = "*"
pytest-xdist = "*"
[packages]
django = "==2.2.7"
django = "*"
django-extensions = "*"
ipython = "*"
django-bootstrap-static = "*"
fontawesome = "*"
psycopg2-binary = "*"
[requires]
python_version = "3.6"
python_version = "3.8"
This diff is collapsed.
version: "3.8"
services:
db:
image: postgres
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
asgiref==3.3.0
backcall==0.2.0
decorator==4.4.2
Django==3.1.3
django-bootstrap-static==4.2.1
django-extensions==3.0.9
fontawesome==5.10.1.post1
ipython==7.19.0
ipython-genutils==0.2.0
jedi==0.17.2
parso==0.7.1
pexpect==4.8.0
pickleshare==0.7.5
prompt-toolkit==3.0.8
ptyprocess==0.6.0
Pygments==2.7.2
pytz==2020.4
sqlparse==0.4.1
traitlets==5.0.5
wcwidth==0.2.5
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
django = "==2.2.7"
django-extensions = "*"
ipython = "*"
[requires]
python_version = "3.6"
{
"_meta": {
"hash": {
"sha256": "7ba12d08e66531f0e0cde29a725d7ac36b8e1a32ab75415099fb7a9359b0bf56"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.6"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"backcall": {
"hashes": [
"sha256:38ecd85be2c1e78f77fd91700c76e14667dc21e2713b63876c0eb901196e01e4",
"sha256:bbbf4b1e5cd2bdb08f915895b51081c041bac22394fdfcfdfbe9f14b77c08bf2"
],
"version": "==0.1.0"
},
"decorator": {
"hashes": [
"sha256:54c38050039232e1db4ad7375cfce6748d7b41c29e95a081c8a6d2c30364a2ce",
"sha256:5d19b92a3c8f7f101c8dd86afd86b0f061a8ce4540ab8cd401fa2542756bce6d"
],
"version": "==4.4.1"
},
"django": {
"hashes": [
"sha256:4025317ca01f75fc79250ff7262a06d8ba97cd4f82e93394b2a0a6a4a925caeb",
"sha256:a8ca1033acac9f33995eb2209a6bf18a4681c3e5269a878e9a7e0b7384ed1ca3"
],
"index": "pypi",
"version": "==2.2.6"
},
"django-extensions": {
"hashes": [
"sha256:a9db7c56a556d244184f589f2437b4228de86ee45e5ebb837fb20c6d54e95ea5",
"sha256:b58320d3fe3d6ae7d1d8e38959713fa92272f4921e662d689058d942a5b444f7"
],
"index": "pypi",
"version": "==2.2.5"
},
"ipython": {
"hashes": [
"sha256:dfd303b270b7b5232b3d08bd30ec6fd685d8a58cabd54055e3d69d8f029f7280",
"sha256:ed7ebe1cba899c1c3ccad6f7f1c2d2369464cc77dba8eebc65e2043e19cda995"
],
"index": "pypi",
"version": "==7.9.0"
},
"ipython-genutils": {
"hashes": [
"sha256:72dd37233799e619666c9f639a9da83c34013a73e8bbc79a7a6348d93c61fab8",
"sha256:eb2e116e75ecef9d4d228fdc66af54269afa26ab4463042e33785b887c628ba8"
],
"version": "==0.2.0"
},
"jedi": {
"hashes": [
"sha256:786b6c3d80e2f06fd77162a07fed81b8baa22dde5d62896a790a331d6ac21a27",
"sha256:ba859c74fa3c966a22f2aeebe1b74ee27e2a462f56d3f5f7ca4a59af61bfe42e"
],
"version": "==0.15.1"
},
"parso": {
"hashes": [
"sha256:63854233e1fadb5da97f2744b6b24346d2750b85965e7e399bec1620232797dc",
"sha256:666b0ee4a7a1220f65d367617f2cd3ffddff3e205f3f16a0284df30e774c2a9c"
],
"version": "==0.5.1"
},
"pexpect": {
"hashes": [
"sha256:2094eefdfcf37a1fdbfb9aa090862c1a4878e5c7e0e7e7088bdb511c558e5cd1",
"sha256:9e2c1fd0e6ee3a49b28f95d4b33bc389c89b20af6a1255906e90ff1262ce62eb"
],
"markers": "sys_platform != 'win32'",
"version": "==4.7.0"
},
"pickleshare": {
"hashes": [
"sha256:87683d47965c1da65cdacaf31c8441d12b8044cdec9aca500cd78fc2c683afca",
"sha256:9649af414d74d4df115d5d718f82acb59c9d418196b7b4290ed47a12ce62df56"
],
"version": "==0.7.5"
},
"prompt-toolkit": {
"hashes": [
"sha256:46642344ce457641f28fc9d1c9ca939b63dadf8df128b86f1b9860e59c73a5e4",
"sha256:e7f8af9e3d70f514373bf41aa51bc33af12a6db3f71461ea47fea985defb2c31",
"sha256:f15af68f66e664eaa559d4ac8a928111eebd5feda0c11738b5998045224829db"
],
"version": "==2.0.10"
},
"ptyprocess": {
"hashes": [
"sha256:923f299cc5ad920c68f2bc0bc98b75b9f838b93b599941a6b63ddbc2476394c0",
"sha256:d7cc528d76e76342423ca640335bd3633420dc1366f258cb31d05e865ef5ca1f"
],
"version": "==0.6.0"
},
"pygments": {
"hashes": [
"sha256:71e430bc85c88a430f000ac1d9b331d2407f681d6f6aec95e8bcfbc3df5b0127",
"sha256:881c4c157e45f30af185c1ffe8d549d48ac9127433f2c380c24b84572ad66297"
],
"version": "==2.4.2"
},
"pytz": {
"hashes": [
"sha256:1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d",
"sha256:b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be"
],
"version": "==2019.3"
},
"six": {
"hashes": [
"sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c",
"sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73"
],
"version": "==1.12.0"
},
"sqlparse": {
"hashes": [
"sha256:40afe6b8d4b1117e7dff5504d7a8ce07d9a1b15aeeade8a2d10f130a834f8177",
"sha256:7c3dca29c022744e95b547e867cee89f4fce4373f3549ccd8797d8eb52cdb873"
],
"version": "==0.3.0"
},
"traitlets": {
"hashes": [
"sha256:70b4c6a1d9019d7b4f6846832288f86998aa3b9207c6821f3578a6a6a467fe44",
"sha256:d023ee369ddd2763310e4c3eae1ff649689440d4ae59d7485eb4cfbbe3e359f7"
],
"version": "==4.3.3"
},
"wcwidth": {
"hashes": [
"sha256:3df37372226d6e63e1b1e1eda15c594bca98a22d33a23832a90998faa96bc65e",
"sha256:f4ebe71925af7b40a864553f761ed559b43544f8f71746c2d756c7fe788ade7c"
],
"version": "==0.1.7"
}
},
"develop": {}
}
File mode changed from 100755 to 100644
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
django = "==2.2.7"
django-extensions = "*"
ipython = "*"
[requires]
python_version = "3.6"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment