If you can't read please download the document
Upload
raul-espinola
View
847
Download
0
Embed Size (px)
Citation preview
1. Introduccin a Django Manuel Kaufmann Octubre de 2008 http://www.python.com.ar 2. Introduccin a Django Qu es Django?
Para qu se utiliza?
Historia
3. Introduccin a Django Patrn de diseo MVC
Modelo (models.py)
Vista (views.py)
Plantillas (index.html)
4. Introduccin a Django Instalacin [ humitos ]$ wget -c http://www.djangoproject.com/download/1.0/tarball/ [ humitos ]$ tar xzvf Django-1.0.tar.gz ...... [ humitos ]$ cd Django-1.0 [ humitos ]$ sudo python setup.py install Prueba [ humitos ]$ python Python 2.5.2 (r252:60911, Aug6 2008, 09:17:29) [GCC 4.3.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> django.VERSION (1, 0, 'final') >>> 5. Introduccin a Django Comenzar un proyecto It worked!
Archivos del proyecto
[ humitos ]$ django-admin.py startproject blog [ humitos ]$ ls blog/ __init__.pymanage.pysettings.pyurls.py [ humitos ]$ python manage.py runserver 6. Introduccin a Django Mapear URL's
Expresiones regulares
Funcin para la url
7. Introduccin a Django Qu es una aplicacin?
Cul es la diferencia con un proyecto?
Ejemplo [ humitos ]$ python manage.py startapp posts
8. Introduccin a Django Modelos
Configuracin del motor
Definicin de los modelos DATABASE_ENGINE = ' sqlite3 ' DATABASE_NAME = ' /home/humitos/blog/database.db ' DATABASE_USER = '' ...
9. Introduccin a Django Definicin de modelos Modelo 'Post'
fromdjango.dbimportmodels classPost(models.Model): titulo = models.CharField(max_length= 50 ) contenido = models.TextField() etiquetas = models.ManyToManyField(Etiqueta) [ humitos ]$ python manage.py sql posts 10. Introduccin a Django Definicin de modelos Instalar la aplicacin
classEtiqueta(models.Model): nombre = models.CharField(max_length= 25 ) classComentario(models.Model): autor = models.CharField(max_length= 25 ) contenido = models.TextField() post = models.ForeignKey(Post) 11. Introduccin a Django Sistema de administracin
Instalacin
Agregar nuestros modelos
12. Introduccin a Django Vistas
Primer vista
Agregar nuestros modelos
13. Introduccin a Django Ejemplo fromdjango.shortcutsimportrender_to_response fromdjango.httpimportHttpResponseRedirect fromblog.posts.modelsimportPostForm, Post defagregar_post(request): ifrequest.method == ' GET ': formulario = PostForm() returnrender_to_response(' agregar_post.html ', {' formulario ': formulario}) else : formulario = PostForm(request.POST) ifformulario.is_valid(): formulario.save() returnHttpResponseRedirect(' / ') 14. Introduccin a Django Sistema de plantillas
Herencia
Etiquetas
15. Introduccin a Django Sistema de plantillas
Filtros
Extensin
16. Introduccin a Django Preguntas? Preguntas? Preguntas? Preguntas? Preguntas? Preguntas? Preguntas? Preguntas? Preguntas? Preguntas? 17. Introduccin a Django Manuel Kaufmann [email_address] Muchas Gracias! Comunidad Django: