Your SlideShare is downloading. ×
0
Para perfeccionistas con  deadlines <ul><li>Leo Soto M. </li></ul><ul><li>Imagemaker IT </li></ul><ul><li>Encuentro Linux ...
¿Python? ¿Django?
Python is an experiment in how much freedom programmers need...
...Too much freedom and nobody can read another's code; too little and expressiveness is endangered <ul><ul><li>- Guido va...
Django
Simple
Flexible
Pragmático
Models Templates
Models Templates Forms Auth
Models Templates Admin Forms Auth
Models Templates Admin Forms Auth i18n
Models Templates Admin Forms Auth i18n GIS
Models Templates Admin Forms Auth i18n GIS Comments DataBrowse Caching
Models Templates Admin Forms Auth i18n GIS Comments DataBrowse Syndication Sitemaps Caching
Models Templates Admin Forms Auth i18n GIS Comments DataBrowse Syndication Sitemaps django-evolution django-registration d...
Eehhh...
Alto!
Código > Blabla
 
Proyecto: “eldemo” App: “elinux”
1. Modelos
# eldemo/elinux/models.py: from django.db import models from datetime import date class Noticia(models.Model):   fecha = m...
class Expositor(models.Model):   nombre = models.CharField(max_length=80,   unique=True)   foto = models.ImageField(   upl...
class Charla(models.Model):   titulo = models.CharField(max_length=120,   unique=True)   expositor = models.ForeignKey(Exp...
¿SQL?
¿SQL? R: Lo genera Django
BEGIN; CREATE TABLE &quot;elinux_noticia&quot; (   &quot;id&quot; serial NOT NULL PRIMARY KEY,   &quot;titulo&quot; varcha...
# Python: class Charla(models.Model):   titulo = models.CharField(max_length=120,   unique=True)   expositor = models.Fore...
Bonus
from django.contrib import admin from elinux.models import Noticia, Expositor,   Charla admin.site.register(Expositor) adm...
 
 
 
 
 
 
 
 
from django.contrib import admin from elinux.models import Noticia, Expositor,   Charla class ExpositorAdmin(model.ModelAd...
 
 
 
from django.contrib import admin from elinux.models import Noticia, Expositor,   Charla class ExpositorAdmin(model.ModelAd...
 
from django.contrib import admin from elinux.models import Noticia, Expositor,   Charla class ExpositorAdmin(model.ModelAd...
 
 
2. Vistas
URLs
urlpatterns = patterns('eldemo.elinux.views',   (r'^$', 'index'),   (r'^noticias/$', 'noticias'),   (r'^noticias/([0-9]+)/...
 
def index(request):   noticias = Noticia.objects.all()   ultimas_noticias = noticias[:3]   return render_to_response(   &q...
def noticias(request):   noticias = Noticia.objects.all()   return render_to_response(   &quot;elinux/noticias.html&quot;,...
def expositores_invitados(request):   expositores = Expositor.objects.filter(   invitado=True)   return render_to_response...
3. Templates
Plantilla Base
<body id=&quot;page_bg&quot; class=&quot;red&quot;>   <a name=&quot;up&quot; id=&quot;up&quot;></a>   <div class=&quot;cen...
<!-- Lo Importante: --> ...  <div id=&quot;mainbody&quot;>   {% block content %}{% endblock %} </div> ...
Luego...
<!-- index.html --> {% extends &quot;base.html&quot; %} {% block content %} ... {% for noticia in  noticias  %} <p> <stron...
 
Bonus: Forms
from django import forms class ContactForm(forms.Form):   nombre =  forms .CharField(max_length=200)   email =  forms .Ema...
def contacto(request):   if request.method == 'POST':    form = ContactForm(request.POST)   if form.is_valid():   # TODO: ...
{% extends &quot;base.html&quot; %} {% block content %} <form action=&quot;.&quot; method=&quot;POST&quot;> <table> {{ for...
 
 
 
Más Ideas y Posibilidades...
Ubicacion Geográfica de los Asistentes
Comentarios
Ejecución en la JVM (via Jython)
Feeds
Feeds (Oh, pero eso es demasiado fácil)
from django.contrib.syndication.feeds import Feed from elinux.models import Noticia class NoticiasFeed(Feed):   title = &q...
 
El framework web para perfeccionistas con deadlines 3. Templates
¿Preguntas?
Gracias! leo.soto@gmail.com  http://blog.leosoto.com
Imágenes (Créditos)   Desde Flickr (licenciadas vía Creative Commons):   http://www.flickr.com/photos nothingpersonal/2525...
Upcoming SlideShare
Loading in...5
×

Django, el framework web para perfeccionistas con deadlines

2,340

Published on

Presentación hecha en el Encuentro Linux 2008

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,340
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
70
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Transcript of "Django, el framework web para perfeccionistas con deadlines"

    1. 1. Para perfeccionistas con deadlines <ul><li>Leo Soto M. </li></ul><ul><li>Imagemaker IT </li></ul><ul><li>Encuentro Linux 2008 </li></ul>
    2. 2. ¿Python? ¿Django?
    3. 3. Python is an experiment in how much freedom programmers need...
    4. 4. ...Too much freedom and nobody can read another's code; too little and expressiveness is endangered <ul><ul><li>- Guido van Rossum </li></ul></ul><ul><ul><li>(Agosto 1996) </li></ul></ul>
    5. 5. Django
    6. 6. Simple
    7. 7. Flexible
    8. 8. Pragmático
    9. 9. Models Templates
    10. 10. Models Templates Forms Auth
    11. 11. Models Templates Admin Forms Auth
    12. 12. Models Templates Admin Forms Auth i18n
    13. 13. Models Templates Admin Forms Auth i18n GIS
    14. 14. Models Templates Admin Forms Auth i18n GIS Comments DataBrowse Caching
    15. 15. Models Templates Admin Forms Auth i18n GIS Comments DataBrowse Syndication Sitemaps Caching
    16. 16. Models Templates Admin Forms Auth i18n GIS Comments DataBrowse Syndication Sitemaps django-evolution django-registration django-jython django-authopenid django-tagging django-command-extensions google-app-engine-django django-search django-contact-form django-contact-form django-bookmarks django-photologue django-timezones django-profile django-mptt Caching Pinax Satchmo
    17. 17. Eehhh...
    18. 18. Alto!
    19. 19. Código > Blabla
    20. 21. Proyecto: “eldemo” App: “elinux”
    21. 22. 1. Modelos
    22. 23. # eldemo/elinux/models.py: from django.db import models from datetime import date class Noticia(models.Model): fecha = models.DateField( default=date.today) titulo = models.CharField(max_length=80) contenido = models.TextField()
    23. 24. class Expositor(models.Model): nombre = models.CharField(max_length=80, unique=True) foto = models.ImageField( upload_to=&quot;fotos&quot;) resena = models.TextField(null=True, blank=True) invitado = models.BooleanField()
    24. 25. class Charla(models.Model): titulo = models.CharField(max_length=120, unique=True) expositor = models.ForeignKey(Expositor)
    25. 26. ¿SQL?
    26. 27. ¿SQL? R: Lo genera Django
    27. 28. BEGIN; CREATE TABLE &quot;elinux_noticia&quot; ( &quot;id&quot; serial NOT NULL PRIMARY KEY, &quot;titulo&quot; varchar(80) NOT NULL, &quot;contenido&quot; text NOT NULL ) ; CREATE TABLE &quot;elinux_expositor&quot; ( &quot;id&quot; serial NOT NULL PRIMARY KEY, &quot;nombre&quot; varchar(80) NOT NULL UNIQUE, &quot;foto&quot; varchar(100) NOT NULL, &quot;resena&quot; text NULL ) ; CREATE TABLE &quot;elinux_charla&quot; ( &quot;id&quot; serial NOT NULL PRIMARY KEY, &quot;titulo&quot; varchar(120) NOT NULL UNIQUE, &quot;expositor_id&quot; integer NOT NULL REFERENCES &quot;elinux_expositor&quot; (&quot;id&quot;) DEFERRABLE INITIALLY DEFERRED ) ; CREATE INDEX &quot;elinux_charla_expositor_id&quot; ON &quot;elinux_charla&quot; (&quot;expositor_id&quot;); COMMIT;
    28. 29. # Python: class Charla(models.Model): titulo = models.CharField(max_length=120, unique=True) expositor = models.ForeignKey(Expositor) -- SQL: CREATE TABLE &quot;elinux_charla&quot; ( &quot;id&quot; serial NOT NULL PRIMARY KEY, &quot;titulo&quot; varchar(120) NOT NULL UNIQUE, &quot;expositor_id&quot; integer NOT NULL REFERENCES &quot;elinux_expositor&quot; (&quot;id&quot;) DEFERRABLE INITIALLY DEFERRED ); CREATE INDEX &quot;elinux_charla_expositor_id&quot; ON &quot;elinux_charla&quot; (&quot;expositor_id&quot;);
    29. 30. Bonus
    30. 31. from django.contrib import admin from elinux.models import Noticia, Expositor, Charla admin.site.register(Expositor) admin.site.register(Charla) admin.site.register(Noticia)
    31. 40. from django.contrib import admin from elinux.models import Noticia, Expositor, Charla class ExpositorAdmin(model.ModelAdmin): search_fields = ('nombre', 'resena') list_filter = ('invitado',) admin.site.register(Expositor, ExpositorAdmin ) admin.site.register(Charla) admin.site.register(Noticia)
    32. 44. from django.contrib import admin from elinux.models import Noticia, Expositor, Charla class ExpositorAdmin(model.ModelAdmin): search_fields = ('nombre', 'resena') list_filter = ('invitado',) class CharlaAdmin(model.ModelAdmin): list_display = ('titulo', 'expositor') admin.site.register(Expositor, ExpositorAdmin) admin.site.register(Charla, CharlaAdmin ) admin.site.register(Noticia)
    33. 46. from django.contrib import admin from elinux.models import Noticia, Expositor, Charla class ExpositorAdmin(model.ModelAdmin): search_fields = ('nombre', 'resena') list_filter = ('invitado',) class CharlaAdmin(model.ModelAdmin): list_display = ('titulo', 'expositor') class NoticiaAdmin(model.ModelAdmin): date_hierarchy = ('fecha') admin.site.register(Expositor, ExpositorAdmin) admin.site.register(Charla, CharlaAdmin) admin.site.register(Noticia, NoticiaAdmin )
    34. 49. 2. Vistas
    35. 50. URLs
    36. 51. urlpatterns = patterns('eldemo.elinux.views', (r'^$', 'index'), (r'^noticias/$', 'noticias'), (r'^noticias/([0-9]+)/$', 'noticia'), (r'^expositores/invitados/$', 'expositores_invitados'), (r'^expositores/seleccionados/$', 'expositores_seleccionados') )
    37. 53. def index(request): noticias = Noticia.objects.all() ultimas_noticias = noticias[:3] return render_to_response( &quot;elinux/index.html&quot;, {'noticias': ultimas_noticias})
    38. 54. def noticias(request): noticias = Noticia.objects.all() return render_to_response( &quot;elinux/noticias.html&quot;, {'noticias': noticias}) def noticia(request, id_noticia): noticia = Noticia.objects.get( id=id_noticia) return render_to_response( &quot;elinux/noticia.html&quot;, {'noticia': noticia})
    39. 55. def expositores_invitados(request): expositores = Expositor.objects.filter( invitado=True) return render_to_response( &quot;elinux/expositores.html&quot;, {'expositores': expositores})
    40. 56. 3. Templates
    41. 57. Plantilla Base
    42. 58. <body id=&quot;page_bg&quot; class=&quot;red&quot;> <a name=&quot;up&quot; id=&quot;up&quot;></a> <div class=&quot;center&quot;> <div id=&quot;wrapper&quot;> <div id=&quot;top&quot;> <div> <div> <span id=&quot;logo&quot; style=&quot;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://2008.encuentrolinux.cl/templates/linux2008/images/omt_logo_trans.png',sizingMethod='scale');&quot;></span> <span id=&quot;logo_header&quot; style=&quot;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://2008.encuentrolinux.cl/templates/linux2008/images/omt_logo_header.png',sizingMethod='scale');&quot;></span> <span id=&quot;joomla&quot; style=&quot;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://2008.encuentrolinux.cl/templates/linux2008/images/omt_joomla_trans.png',sizingMethod='scale');&quot;></span> </div> </div> </div> <div id=&quot;middle&quot;> <div id=&quot;middle_2&quot;> <div id=&quot;middle_3&quot;> <div id=&quot;middle_4&quot;> <div id=&quot;navigation&quot;> <div id=&quot;centernav&quot;> <span id=&quot;topnav&quot;> <ul id=&quot;mainlevel&quot;> <li class=&quot;red_active_menu&quot;> <a href=&quot;{% url eldemo.elinux.views.index %}&quot;>Inicio</a></li> <ul id=&quot;mainlevel&quot;> <li class=&quot;red&quot;> <a href=&quot;{% url eldemo.elinux.views.noticias %}&quot;> Noticias </a></li> <li class=&quot;red&quot;><a href=&quot;http://2008.encuentrolinux.cl/index.php?option=com_content&amp;task=view&amp;id=24&amp;Itemid=68&quot;>Inscripción</a></li> <li class=&quot;red&quot;><a href=&quot;http://2008.encuentrolinux.cl/index.php?option=com_content&amp;task=view&amp;id=13&amp;Itemid=28&quot;>Participan</a></li> <li class=&quot;red&quot;><a href=&quot;http://2008.encuentrolinux.cl/index.php?option=com_contact&amp;task=view&amp;contact_id=1&amp;Itemid=62&quot;>Contacto</a></li> </ul> </span> <div class=&quot;clr&quot;></div> </div> </div> <div id=&quot;contentarea&quot;> <table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;100%&quot; class=&quot;contentarea&quot;> <tr valign=&quot;top&quot;> <td id=&quot;leftborder&quot;> <div id=&quot;pathway&quot;> <span class=&quot;pathway&quot;> <a href=&quot;http://2008.encuentrolinux.cl/index.php&quot; class=&quot;pathway&quot;>Inicio</a> <img src=&quot;http://2008.encuentrolinux.cl/templates/linux2008/images/arrow.png&quot; border=&quot;0&quot; alt=&quot;arrow&quot; /><!-- TODO: Contacto --> </span> </div> <div id=&quot;mainbody&quot;> {% block content %} {% endblock %} </div> </td> </tr> </table> </div> </div> </div> </div> </div> <div id=&quot;bottom&quot;> <div> <div>Encuentro Linux 2008 / <a href=&quot;index.php?option=com_contact&amp;Itemid=3&quot; target=&quot;_parent&quot;>Contacto</a></div> </div> </div> </div> </div> </body>
    43. 59. <!-- Lo Importante: --> ... <div id=&quot;mainbody&quot;> {% block content %}{% endblock %} </div> ...
    44. 60. Luego...
    45. 61. <!-- index.html --> {% extends &quot;base.html&quot; %} {% block content %} ... {% for noticia in noticias %} <p> <strong>{{ noticia.titulo }}</strong> {{ noticia.contenido|truncatewords:6 }} <a href=&quot;{% url eldemo.elinux.views.noticia noticia.id %}&quot;>(ver más)</a> </p> {% endfor %} {% endblock %}
    46. 63. Bonus: Forms
    47. 64. from django import forms class ContactForm(forms.Form): nombre = forms .CharField(max_length=200) email = forms .EmailField() titulo = forms .CharField(max_length=200) texto = forms .CharField( widget=forms.Textarea)
    48. 65. def contacto(request): if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): # TODO: Enviar el mail return HttpResponseRedirect('/') else: form = ContactForm() return render_to_response( &quot;elinux/contacto.html&quot;, {'form': form})
    49. 66. {% extends &quot;base.html&quot; %} {% block content %} <form action=&quot;.&quot; method=&quot;POST&quot;> <table> {{ form.as_table }} </table> <input type=&quot;submit&quot; value=&quot;Enviar&quot; > </form> {% endblock %}
    50. 70. Más Ideas y Posibilidades...
    51. 71. Ubicacion Geográfica de los Asistentes
    52. 72. Comentarios
    53. 73. Ejecución en la JVM (via Jython)
    54. 74. Feeds
    55. 75. Feeds (Oh, pero eso es demasiado fácil)
    56. 76. from django.contrib.syndication.feeds import Feed from elinux.models import Noticia class NoticiasFeed(Feed): title = &quot;Noticias ELinux&quot; link = &quot;/noticias&quot; description = &quot;Noticias Encuentro Linux 2008&quot; def items(self): return Noticia.objects.all()
    57. 78. El framework web para perfeccionistas con deadlines 3. Templates
    58. 79. ¿Preguntas?
    59. 80. Gracias! leo.soto@gmail.com http://blog.leosoto.com
    60. 81. Imágenes (Créditos) Desde Flickr (licenciadas vía Creative Commons): http://www.flickr.com/photos nothingpersonal/252531721/ http://www.flickr.com/photos/d_oracle/349073686/ http://www.flickr.com/photos/d_oracle/350780566/ http://www.flickr.com/photos/spine/2425394931/ http://www.flickr.com/photos/nino63004/2471663305/ http://www.flickr.com/photos/ryanricketts/2295726918/ http://www.flickr.com/photos/twatson/2854156629/ http://www.flickr.com/photos/funkybug/1538454520/ http://www.flickr.com/photos/nirak/331916210/
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×