Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bonnegent Sebastien
cours_django
Commits
b741af31
Commit
b741af31
authored
Nov 06, 2019
by
Bonnegent Sebastien
Browse files
correction du cours 1
parent
72171856
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
cours.html
View file @
b741af31
This diff is collapsed.
Click to expand it.
cours.md
View file @
b741af31
...
...
@@ -109,20 +109,6 @@ $ pipenv run ./manage.py generate_secret_key
f#wgrz$@#wh@*x5)_+(*$$^aw(c!q#a4)c0230bwp!iy
~~~
## Pour git
### .gitignore
~~~
*.pyc
conf/settings.py
*/__pycache__
db.sqlite3*
~~~
### Ajout dans git
~~~
$ git add .gitignore
~~~
## Gestion des migrations
### Création (si nécessaire)
~~~
...
...
@@ -169,8 +155,9 @@ créer des groupes de ports / services et gérer plusieurs parefeux différents.
Note: pas de clé primaire !
# À vous de jouer !
## Ports
-
protocole:
tcp
(défaut), udp, icmp
-
protocole:
any
(défaut),
tcp,
udp, icmp
-
début: entier positif, 0 par défaut
-
fin: entier positif, 0 par défaut
...
...
@@ -196,7 +183,11 @@ $ pipenv run ./manage.py migrate
...
~~~
## webui/migrations/0001_initial.py
## Contenu d'une migration
~~~
$ cat webui/migrations/0001_initial.py
~~~
~~~
python
from
django.db
import
migrations
,
models
...
...
@@ -236,13 +227,17 @@ class Migration(migrations.Migration):
<
Port
:
Port
object
(
1
)
>
~~~
## Affichage
## webui/models.py
Modifier l'affichage des instances.
~~~
python
def
__str__
(
self
):
ports
=
f
"
{
self
.
debut
}
"
if
self
.
debut
<
self
.
fin
:
ports
+=
f
"-
{
self
.
fin
}
"
return
f
"
{
ports
}
(
{
self
.
get_protocole_display
()
}
)"
class
Port
(
models
.
Model
):
def
__str__
(
self
):
ports
=
f
"
{
self
.
debut
}
"
if
self
.
debut
<
self
.
fin
:
ports
+=
f
"-
{
self
.
fin
}
"
return
f
"
{
ports
}
(
{
self
.
get_protocole_display
()
}
)"
~~~
## Shell plus
...
...
@@ -262,8 +257,9 @@ def __str__(self):
<
Port
:
80
(
tcp
)
>
,
<
Port
:
25
(
tcp
)
>
]
>
~~~
## Ordre
### webui/models.py
## webui/models.py
Modifier l'ordre des instances.
~~~
python
class
Port
(
models
.
Model
):
...
...
@@ -333,13 +329,9 @@ Out[4]: (1, {'webui.Port': 1})
In
[
5
]:
Port
.
objects
.
all
().
delete
()
~~~
# À vous de jouer !
## Documentation
-
https://docs.djangoproject.com/fr/
-
partie modèle
## webui/models.py
Faire les classes suivantes.
### Adresse
-
nom: chaine de caractères (25)
-
ip: une adresse IP
...
...
@@ -351,3 +343,10 @@ In [5]: Port.objects.all().delete()
-
nom: chaine de caractères (25)
-
ports: une liste de ports
# Documentation
## Django
-
https://docs.djangoproject.com/fr/
-
partie modèle
-
https://docs.djangoproject.com/fr/2.2/intro/tutorial01/
-
tutoriel officiel
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment