Aller au contenu principal
Django Start - Knowledges
⭐ Vedette

Django Quick Start

1min
Temps de lecture
100
Lectures
10
Commentaires
OwlSystems

OwlSystems

Date de publication

TL;DR

Installation et Configuration de django

Installation et Configuration

1. Environnement virtuel

python3 -m venv venv
source venv/bin/activate
pip install django

2. Création projet

django-admin startproject monprojet
cd monprojet
python manage.py startapp monapp

3. Configuration de base (settings.py)

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'monapp',  # Ajouter votre app
]

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'ma_base',
        'USER': 'postgres',
        'PASSWORD': 'motdepasse',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

4. Modèle simple (models.py)

from django.db import models

class Article(models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title

5. Vue basique (views.py)

from django.shortcuts import render
from .models import Article

def article_list(request):
    articles = Article.objects.all()
    return render(request, 'articles/list.html', {'articles': articles})

6. URLs (urls.py)

from django.urls import path
from . import views

urlpatterns = [
    path('articles/', views.article_list, name='article_list'),
]

Commandes Essentielles

# Migrations
python manage.py makemigrations
python manage.py migrate

# Superuser
python manage.py createsuperuser

# Serveur dev
python manage.py runserver

Structure Recommandée

monprojet/
├── manage.py
├── monprojet/
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── monapp/
    ├── models.py
    ├── views.py
    ├── urls.py
    └── templates/

Django 5.0+ - Python 3.8+ requis

OwlSystems

OwlSystems

Parcours méthodologique
10 rue de la mare boutillier
Grisy-Suisnes, 77166
(prix d'un appel local / WhatsApp)
Contactez-nous
Nos bureaux

Présents à Paris et dans toute l'Île-de-France pour vous accompagner

Actualités

Restez informé des dernières actualités cybersécurité

Follow Us