Refont of https://mathese-emoi.fr/ using Django framework
- Bleeding edge django3.2 template focused on code quality and security:
- Wemake-django: https://github.com/wemake-services/wemake-django-template
- wemake-python: https://wemake-python-styleguide.readthedocs.io/en/latest/index.html
- pre-commit: https://pre-commit.com
- isort, autopep8, autoflake, docformatter, unify, flakeheaven
- QuerySets : https://docs.djangoproject.com/en/4.1/ref/models/querysets/#all
- Méthodes sur les relations https://docs.djangoproject.com/en/4.1/ref/models/relations/
from django.contrib.auth.models import User
User.objects.filter(is_superuser=True)
usr = User.objects.get(username='your username')
usr.set_password('raw password')
usr.save()Lien -> https://docs.djangoproject.com/en/4.1/intro/tutorial02/
- Types objects : https://docs.djangoproject.com/en/4.1/ref/models/fields/
- Diagramme de classe fait dans diagram.
- Migration faites (migrate, makemigrations, migrate)
- Ajout d'un objet avec l'onglet admin
-
python manage.py migrateThe migrate command looks at the INSTALLED_APPS setting and creates any necessary database tables according to the database settings in your mysite/settings.py file and the database migrations shipped with the app (we’ll cover those later). You’ll see a message for each migration it applies.
-
python manage.py makemigrations application_nameBy running
makemigrations, you’re telling Django that you’ve made some changes to your models (in this case, you’ve made new ones) and that you’d like the changes to be stored as a migration. -
python manage.py sqlmigrate application_name 0001let’s see what SQL that migration would run
-
python manage.py migrateThe migrate command takes all the migrations that haven’t been applied (Django tracks which ones are applied using a special table in your database called django_migrations) and runs them against your database - essentially, synchronizing the changes you made to your models with the schema in the database.
Lien -> https://docs.djangoproject.com/en/4.1/intro/tutorial03/
- URLdispatcher : https://docs.djangoproject.com/en/4.1/topics/http/urls/
A clean, elegant URL scheme is an important detail in a high-quality web application. Django lets you design URLs however you want, with no framework limitations.
-
Template Polls (Write views that actually do something) => Done
-
Render Done (Index/Detail):
The render() function takes the request object as its first argument, a template name as its second argument and a dictionary as its optional third argument. It returns an HttpResponse object of the given template rendered with the given context.
- Removing hardcoded URLs in templates :
- Dans polls/index.html:
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
- Dans polls/urls.py:
from django.urls import path
from mte_website.polls import views
# the 'name' value as called by the {% url %} template tag
path('<int:question_id>/', views.detail, name='detail'),- Du coup on peut utiliser le tag { % url } dans l'html :
<li><a href="{% url 'detail' question.id %}">{{ question.question_text }}</a></li>-
Si on change l'url dans urls.py, pas d'action à faire dans le template html. Et c'est pris en compte.
-
Namespacing URL names
- Pour différencier les 'detail' de différentes app, on peut ajouter un namespace dans polls/urls.py:
app_name = 'polls' - Puis dans html:
{% url 'detail' question.id %}
- Pour différencier les 'detail' de différentes app, on peut ajouter un namespace dans polls/urls.py:
lien: https://docs.djangoproject.com/en/4.1/intro/tutorial04/
Next : Use generic views: Less code is better
- first page: index qui redirige un accueil
- créer un onglet par application (permanence, blogs, annuaire..)
- commencer par annuaire
- Pour ajouter les onglets avec une fonction : https://docs.djangoproject.com/en/4.2/howto/custom-template-tags/#writing-custom-template-tags Ecrire une fonction qui renvoie les noms des apps à utiliser et les afficher en onglet dans l'html.
- terminer Css
- afficher les structures
- Arborescence css/template
-
https://docs.djangoproject.com/en/4.1/ref/templates/language/#template-inheritance
-
templates/base.html
-
accueil/templates/accueil/index.html qui extend le base.html
-
annuaire/templates/annuaire/index.html qui extend le base.html
-
static/css static/img
-