Django Show

  • 5,670 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
5,670
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
74
Comments
0
Likes
7

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Django Show
  • 2. Um pouco sobre mim ● Formado em Ciência da Computação ● Entusiasta de Python e Django ● Colaborador do DjangoBrasil e do PythonBrasil ● Desenvolvedor na globo.com
  • 3. Django Show não é... ● Um show de uma boy band ● Uma apresentação de um indiano cantando barby girl ● Nem uma demonstração de magia
  • 4. Welcome to the Django!
  • 5. Arquitetura ● Model ● View ● Template
  • 6. Model from django.db import models from datetime import datetime class Link(models.Model): title = models.CharField(max_length = 255) date = models.DateTimeField(default = datetime.now) url = models.URLField(verify_exists = False) description = models.CharField(max_length = 255) def __unicode__(self): return self.description
  • 7. View from django.shortcuts import render_to_response from models import Link def index(request): links = Link.objects.all() return render_to_response('index.html', {'links':links})
  • 8. Template {% extends quot;base.htmlquot; %} {% block content %} {% for link in links %} <p> <a href=quot;{{ link.url }}quot;> {{ link.title }} </a> - {{ link.date|date:quot;d/m/Yquot; }} </p> {% endfor %} {% endblock %}
  • 9. Manipulando os dados >>> from mysite.bookmarks.models import * >>> l = Link() >>> l.title = 'Python Brasil' >>> l.description = 'Site da comunidade Python no Brasil' >>> l.url = 'http://www.pythonbrasil.com.br' >>> l.save() >>> l <Link: Site da comunidade Python no Brasil> >>> l = Link() >>> l.title = 'Django Brasil' >>> l.description = 'Site da comunidade Django no Brasil' >>> l.url = 'http://www.djangobrasil.org' >>> l.save() >>>
  • 10. Geração de Formulários ● Model x View x Template ● Model x View (Forms + Metodos) x Templates
  • 11. from django.forms import ModelForm from models import Link class LinkForm(ModelForm): class Meta: model = Link
  • 12. Interface de Administração ● Model x ModelAdmin
  • 13. from django.contrib import admin from models import Link admin.site.register(Link)
  • 14. Middleware views
  • 15. Middleware MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', )
  • 16. Algumas middlewares ● Session ● Authentication ● Log ● Gzip
  • 17. Mitos e verdades ● Django e monolítico ● Django não escala ● O deploy no Django é difícil e complicado
  • 18. Django e ZODB ● desafio ou loucura? =)
  • 19. import ZODB.config class ZODBConnection(object): def __init__(self): db = ZODB.config.databaseFromURL(zodb_url) connection = db.open() self.root = connection.root() ZODBInstance = ZODBConnection()
  • 20. from djangozodb import ZODBInstance class ZODBSession(object): def process_request(self, request): request.zodb = ZODBInstance
  • 21. Outros exemplos ● Django + SQLAlchemy (tranquil) ● Django + Storm ● Django + CouchDb ● Django + SQLObject ● Django + Seu ORM Favorito ● Django + BigTable on Google App Engine
  • 22. Mais um exemplo ● Django + REST
  • 23. Cache ● Cache em disco ● Cache em memória ● Cache em banco
  • 24. Cache ● Cache em disco ● Cache em memória ● Cache em banco ???? =
  • 25. Deploy ● Apache = mod_python ● Apache = mod_wsgi ● Apache = fast_cgi ● Lighttpd = fast_cgi ● Nginx = fast_cgi ● ...
  • 26. Em todo lugar... ● Cpython ● Jython ● IronPython ● PyPy ?????
  • 27. Em todo lugar... ● Cpython ● Jython ● IronPython ● PyPy =)
  • 28. Extra ● Authentication Backend ● Signals ● Django + {{ sua template system }}
  • 29. Duvidas? ● Andrews Medina ● andrewsmedina@gmail.com ● http://www.andrewsmedina.com