Démarrer un projet Django Xavier Ordoquy Environnement virtuel • virtualenv / virtualenvwrapper • pip • utilisez les fichiers requirements.txt !!! • $ pip install Django Création • $ django-admin.py startproject demo $ find demo demo demo/manage.py demo/demo demo/demo/__init__.py demo/demo/settings.py demo/demo/urls.py demo/demo/wsgi.py $ mkdir demo/media $ mkdir demo/theme MEDIA et STATIC • STATIC: fichiers projet • MEDIA: fichiers utilisateur • Utilisez Apache / Nginx / ... en production settings.py from os.path import dirname, join, normpath DEBUG = True PROJECT_ROOT = normpath(join('..', dirname(__file__))) MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media') STATIC_URL = '/static/' STATICFILES_DIRS += (join(PROJECT_ROOT, 'theme'),) INSTALLED_APPS += (django.contrib.staticfiles,) urls.py from django.conf import settings from django.conf.urls.static import static urlpatterns = ( ... ) urlpatterns += static( settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) Django debug toolbar DjDT templates contexte SQL configuration $ pip install django-debug-toolbar INTERNAL_IPS = ('127.0.0.1',) INSTALLED_APPS = ( ... 'debug_toolbar', ) MIDDLEWARE_CLASSES = ( # ... 'debug_toolbar.middleware.DebugToolbarMiddleware', # ... ) Sentry / Raven configuration $ pip install django-debug-toolbar INSTALLED_APPS += ('raven.contrib.django',) SENTRY_DSN = http://fb..18:[email protected]/12 Applications génériques Générique • Packaging Python: • facilité d’installation • gestion des dépendances • pypi.python.org ? • Prévoir un système de migration Générique • GenericForeignKey • Garder en dehors du projet Trucs et astuces generic class based views pour les prototypes Mettez votre thème dans une application Utilisez Debug Toolbar pour comprendre l’ORM Il existe une application tiers: www.djangopackages.com pypi.python.org irc: #django-fr Don’t ask to ask Liens http://www.doughellmann.com/projects/virtualenvwrapper/ http://pypi.python.org/pypi/virtualenv https://github.com/django-debug-toolbar/django-debug-toolbar https://www.getsentry.com/docs/ Questions ? [email protected] @linovia_net irc: #django-fr