Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django, Tips and Tricks

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Django, Tips and Tricks

Avatar for Ricardo Iván

Ricardo Iván

February 24, 2015

Other Decks in Programming

Transcript

  1. ¿De que vamos a hablar? • Code Styles • Django

    Environments & Settings • Project Structure • App Design y más ...
  2. ¿Y eso como se hace? En su carpeta del proyecto:

    djangoproject/ manage.py djangoproject/ urls.py wsgi.py settings/ __init__.py development.py production.py
  3. ¿Y eso como se hace? Pt. 2 Via command line

    python manage.py runserver --settings=project.settings.development ------------------------------------------------------------------------------------------------- Via manage.py file # manage.py import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings.development")
  4. Databases Si tienes más de un ambiente: > Usa el

    mismo engine en todos Si planeas cambiar de ambiente: > Cambia tu base de datos lo antes posible
  5. Database auth # /etc/environment export APP_KEY=“hash” export DB_USER=”user” export DB_PASS=”pass”

    # settings/*.py from os import environ environ[‘APP_KEY’] environ[‘DB_USER’] environ[‘DB_PASS’]
  6. Project File Structure project_folder/ documents/ codebase/ djangoproject/ manage.py djangoproject/ __init__.py

    urls.py wsgi.py settings/ __init__.py development.py production.py django-admin.py startproject project djangoproject/ manage.py djangoproject/ __init__.py settings.py urls.py wsgi.py VCS (Git, HG, SVN)
  7. Django Apps o cómo comerte al elefante Explícala en una

    oración simple Si tienes que usar más de un «y» algo va mal “The art of creating and maintaining a good Django app is that it should follow the truncated Unix philosophy according to Douglas Mcllroy: «Write programs that do one thing and do it well.»”
  8. Django Models ¿El model va tener muchos registros o harás

    consultas a este modelo muchas veces usando algún campo en especial [nombre, tipo, etc.]? db_index=True
  9. Django Extended User Model from django.contrib.auth.models import User class UserData(models.Model):

    matricula = CharField(max_length=9, db_index=True) carrera = CharField(max_length=140) user = OneToOneField(User) # user = ForeignKey(User, related_name=”data”)
  10. Instalación sudo pip install pyjade # settings.py TEMPLATE_LOADERS = (

    ('pyjade.ext.django.Loader', ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', )), )