Download - Mini Curso de Django
![Page 1: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/1.jpg)
Welcome to the Django!
![Page 2: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/2.jpg)
What's Django?
"Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design."
from http://www.djangoproject.com/
"...and not a CMS System."
![Page 3: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/3.jpg)
Origins...
Django Reinhardt
![Page 4: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/4.jpg)
Origins...
Lawrence-Journal World
![Page 5: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/5.jpg)
Origins...
Pycon 2005 - Adrian Holovaty e Simon WillisonBSD License*Django Software Foundation - 2008
* http://en.wikipedia.org/wiki/BSD_licenses
![Page 6: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/6.jpg)
www.djangoproject.com
![Page 7: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/7.jpg)
Skills
Convention Over Configuration Object-Relational Mapping (ORM)Very useful admin CRUDForm handlingElegant URL DesignTemplate systemCache systemi18n
![Page 8: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/8.jpg)
Principles (...or philosophies)
DRY (Don't Repeat Yourself )Loose coupling Write less code as possibleQuick developmentExplicit is better than implicit
![Page 9: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/9.jpg)
...and the best, is
![Page 10: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/10.jpg)
MVC? No... MTV!
![Page 11: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/11.jpg)
MVC vs. MTV
Model --> ModelView --> TemplateController --> View
![Page 12: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/12.jpg)
Overview
![Page 13: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/13.jpg)
Go to the Project!
![Page 14: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/14.jpg)
Download
djangoproject.com/download
InstallUnzip Django-x.x.tar.gzpython setup.py install
Or... apt-get install python-django (Debian like OS)
Setting up...
![Page 15: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/15.jpg)
Create a Project...
django-admin.py startproject my_project
![Page 16: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/16.jpg)
Setup files
__init__.py - indicates a python package
manager.py - admin tasks
settings.py - project settings
urls.py - project urls map
![Page 17: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/17.jpg)
Let's to do something...
Open settings.py:DATABASE_ENGINE = 'sqlite3'DATABASE_NAME = 'myblog.db'add 'django.contrib.admin'
Open urls.py:Uncomment the line: "from django.contrib... "Uncomment the line: "admin.autodiscover()... "Uncomment the line: "(r'^admin... "
![Page 18: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/18.jpg)
Development server
python manager.py syncdb
python manager.py runserver [8000]
![Page 19: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/19.jpg)
Others Servers...
Development Server
Apache + Mod_Python
Apache + FastCGI
![Page 20: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/20.jpg)
Create the app
python manage.py startapp my_blog
![Page 21: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/21.jpg)
Setup files
init.py - indicates a python package
models.py - app domain model
views.py - project controller
![Page 22: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/22.jpg)
App x Project
App - web app that do something. E.g. XXX
Project - lot of apps and themselves settings. A project can be a lot of apps, and a app can stay in severals projects
![Page 23: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/23.jpg)
Create the model
Open models.py and edit: from django.db import models
class Artigo(models.Model):titulo = models.CharField(max_length=100)conteudo = models.TextField()publicacao = models.DateTimeField()
![Page 24: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/24.jpg)
Setting the model classes to admin
Open admin.py and edit: from django.contrib import adminfrom models import Artigo admin.site.register(Artigo)
![Page 25: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/25.jpg)
Add the app to the admin
Open settings.py and add:"my_project.blog"
Re-sync the database
Re-run the development server
![Page 26: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/26.jpg)
Setting the urls
Open the urls.py and edit:
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:from django.contrib import adminadmin.autodiscover()
from my_blog.models import Artigo
urlpatterns = patterns('',(r'^$', 'django.views.generic.date_based.archive_index',{'queryset': Artigo.objects.all(), 'date_field': 'publicacao'}),(r'^admin/(.*)', admin.site.root),
)
![Page 27: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/27.jpg)
Setting the templates
Create templates/blog/artigo_archive.html and edit:
<html><body>
<h1>Meu blog</h1>
{% for artigo in latest %}<h2>{{ artigo.titulo }}</h2>
{{ artigo.conteudo }}{% endfor %}
</body></html>
![Page 28: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/28.jpg)
Look your app!
http://localhost:8000/
![Page 29: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/29.jpg)
Recap...
Django is easyDjango is funDjango scalesDjango is maintainableDjango saves small kittensIt rocks - USE IT!
![Page 30: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/30.jpg)
Sites powered by Python/Django
![Page 31: Mini Curso de Django](https://reader034.vdocuments.us/reader034/viewer/2022051111/554e70e8b4c905f66a8b4a8f/html5/thumbnails/31.jpg)