SlideShare uma empresa Scribd logo
1 de 32
Baixar para ler offline
Welcome to the Django!
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."
Origins...




             Django Reinhardt
Origins...




             Lawrence-Journal World
Origins...



   Pycon 2005 - Adrian Holovaty e Simon Willison
   BSD License*
   Django Software Foundation - 2008




 * http://en.wikipedia.org/wiki/BSD_licenses
www.djangoproject.com
Skills


  Convention Over Configuration
  Object-Relational Mapping (ORM)
  Very useful admin CRUD
  Form handling
  Elegant URL Design
  Template system
  Cache system
  i18n
Principles (...or philosophies)



  DRY (Don't Repeat Yourself )
  Loose coupling
  Write less code as possible
  Quick development
  Explicit is better than implicit
...and the best, is
MVC? No... MTV!
MVC vs. MTV



 Model --> Model
 View --> Template
 Controller --> View
Overview
Go to the Project!
Setting up...


  Download
    djangoproject.com/download

  Install
      Unzip Django-x.x.tar.gz
      python setup.py install

  Or... apt-get install python-django (Debian like OS)
Create a Project...




  django-admin.py startproject my_project
Setup files


  __init__.py - indicates a python package

  manager.py - admin tasks

  settings.py - project settings

  urls.py - project urls map
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... "
Development server




 python manager.py syncdb

 python manager.py runserver [8000]
Others Servers...


  Development Server

  Apache + Mod_Python

  Apache + FastCGI
Create the app




 python manage.py startapp my_blog
Setup files


  init.py - indicates a python package

  models.py - app domain model

  views.py - project controller
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
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()
Setting the model classes to admin


    Open admin.py and edit:


from django.contrib import admin
from models import Artigo

admin.site.register(Artigo)
Add the app to the admin


  Open settings.py and add:
  "my_project.blog"

  Re-sync the database

  Re-run the development server
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 admin
admin.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),
)
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>
Look your app!




 http://localhost:8000/
Recap...



  Django is easy
  Django is fun
  Django scales
  Django is maintainable
  Django saves small kittens
  It rocks - USE IT!
Sites powered by Python/Django
Contact/follow us...

           leofernandesmo@gmail.com
            felipe.buarque@gmail.com


                   Twitter:
               @leofernandesmo
                @felipe_wally

Mais conteúdo relacionado

Mais procurados

A To-do Web App on Google App Engine
A To-do Web App on Google App EngineA To-do Web App on Google App Engine
A To-do Web App on Google App EngineMichael Parker
 
Web Crawling Modeling with Scrapy Models #TDC2014
Web Crawling Modeling with Scrapy Models #TDC2014Web Crawling Modeling with Scrapy Models #TDC2014
Web Crawling Modeling with Scrapy Models #TDC2014Bruno Rocha
 
Dynamic Business Processes using Automated Actions
Dynamic Business Processes using Automated ActionsDynamic Business Processes using Automated Actions
Dynamic Business Processes using Automated ActionsDaniel Reis
 
How I Became a WordPress Hacker
How I Became a WordPress HackerHow I Became a WordPress Hacker
How I Became a WordPress HackerMike Zielonka
 
Task Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue
Task Scheduling and Asynchronous Processing Evolved. Zend Server Job QueueTask Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue
Task Scheduling and Asynchronous Processing Evolved. Zend Server Job QueueSam Hennessy
 
Introducere in web
Introducere in webIntroducere in web
Introducere in webAlex Eftimie
 
Odoo - CMS performances optimization
Odoo - CMS performances optimizationOdoo - CMS performances optimization
Odoo - CMS performances optimizationOdoo
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "FDConf
 
TYPO3 User Group - Lausanne - 12 novembre 2013
TYPO3 User Group - Lausanne - 12 novembre 2013TYPO3 User Group - Lausanne - 12 novembre 2013
TYPO3 User Group - Lausanne - 12 novembre 2013dfeyer
 
An Overview of Models in Django
An Overview of Models in DjangoAn Overview of Models in Django
An Overview of Models in DjangoMichael Auritt
 
Views Style Plugins
Views Style PluginsViews Style Plugins
Views Style Pluginsmwrather
 
Google App Engine with Gaelyk
Google App Engine with GaelykGoogle App Engine with Gaelyk
Google App Engine with GaelykChoong Ping Teo
 

Mais procurados (20)

A To-do Web App on Google App Engine
A To-do Web App on Google App EngineA To-do Web App on Google App Engine
A To-do Web App on Google App Engine
 
Web Crawling Modeling with Scrapy Models #TDC2014
Web Crawling Modeling with Scrapy Models #TDC2014Web Crawling Modeling with Scrapy Models #TDC2014
Web Crawling Modeling with Scrapy Models #TDC2014
 
Svelte JS introduction
Svelte JS introductionSvelte JS introduction
Svelte JS introduction
 
Dynamic Business Processes using Automated Actions
Dynamic Business Processes using Automated ActionsDynamic Business Processes using Automated Actions
Dynamic Business Processes using Automated Actions
 
How I Became a WordPress Hacker
How I Became a WordPress HackerHow I Became a WordPress Hacker
How I Became a WordPress Hacker
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Task Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue
Task Scheduling and Asynchronous Processing Evolved. Zend Server Job QueueTask Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue
Task Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue
 
Selenium&amp;scrapy
Selenium&amp;scrapySelenium&amp;scrapy
Selenium&amp;scrapy
 
Introducere in web
Introducere in webIntroducere in web
Introducere in web
 
Odoo - CMS performances optimization
Odoo - CMS performances optimizationOdoo - CMS performances optimization
Odoo - CMS performances optimization
 
codeigniter
codeignitercodeigniter
codeigniter
 
"Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native ""Service Worker: Let Your Web App Feel Like a Native "
"Service Worker: Let Your Web App Feel Like a Native "
 
TYPO3 User Group - Lausanne - 12 novembre 2013
TYPO3 User Group - Lausanne - 12 novembre 2013TYPO3 User Group - Lausanne - 12 novembre 2013
TYPO3 User Group - Lausanne - 12 novembre 2013
 
Django
DjangoDjango
Django
 
An Overview of Models in Django
An Overview of Models in DjangoAn Overview of Models in Django
An Overview of Models in Django
 
Views Style Plugins
Views Style PluginsViews Style Plugins
Views Style Plugins
 
Google App Engine with Gaelyk
Google App Engine with GaelykGoogle App Engine with Gaelyk
Google App Engine with Gaelyk
 
G* on GAE/J 挑戦編
G* on GAE/J 挑戦編G* on GAE/J 挑戦編
G* on GAE/J 挑戦編
 
Slides
SlidesSlides
Slides
 
Gaelyk
GaelykGaelyk
Gaelyk
 

Destaque

Realizando Simulações de Rede com o NS
Realizando Simulações de Rede com o NSRealizando Simulações de Rede com o NS
Realizando Simulações de Rede com o NSFelipe Queiroz
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in DjangoLakshman Prasad
 
Unchain Your Web Development With Django
Unchain Your Web Development With DjangoUnchain Your Web Development With Django
Unchain Your Web Development With DjangoJoey Wilhelm
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slidejonycse
 
Python for Beginners ( #PyLadiesKyoto Meetup )
Python for Beginners ( #PyLadiesKyoto Meetup )Python for Beginners ( #PyLadiesKyoto Meetup )
Python for Beginners ( #PyLadiesKyoto Meetup )Ai Makabi
 
Python Ecosystem for Beginners - PyCon Uruguay 2013
Python Ecosystem for Beginners - PyCon Uruguay 2013Python Ecosystem for Beginners - PyCon Uruguay 2013
Python Ecosystem for Beginners - PyCon Uruguay 2013Hannes Hapke
 
Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginnersRajKumar Rampelli
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 

Destaque (11)

Realizando Simulações de Rede com o NS
Realizando Simulações de Rede com o NSRealizando Simulações de Rede com o NS
Realizando Simulações de Rede com o NS
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in Django
 
Unchain Your Web Development With Django
Unchain Your Web Development With DjangoUnchain Your Web Development With Django
Unchain Your Web Development With Django
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slide
 
Python for Beginners ( #PyLadiesKyoto Meetup )
Python for Beginners ( #PyLadiesKyoto Meetup )Python for Beginners ( #PyLadiesKyoto Meetup )
Python for Beginners ( #PyLadiesKyoto Meetup )
 
Django
DjangoDjango
Django
 
Python Ecosystem for Beginners - PyCon Uruguay 2013
Python Ecosystem for Beginners - PyCon Uruguay 2013Python Ecosystem for Beginners - PyCon Uruguay 2013
Python Ecosystem for Beginners - PyCon Uruguay 2013
 
Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginners
 
Django
DjangoDjango
Django
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 

Semelhante a Mini Curso de Django

Mini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesMini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesLeonardo Fernandes
 
An Introduction to Django Web Framework
An Introduction to Django Web FrameworkAn Introduction to Django Web Framework
An Introduction to Django Web FrameworkDavid Gibbons
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!David Gibbons
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim Rocha
 
Virtual Environment and Web development using Django
Virtual Environment and Web development using DjangoVirtual Environment and Web development using Django
Virtual Environment and Web development using DjangoSunil kumar Mohanty
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for BeginnersJason Davies
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheetLam Hoang
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگوrailsbootcamp
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to djangoIlian Iliev
 
Build and deploy Python Django project
Build and deploy Python Django projectBuild and deploy Python Django project
Build and deploy Python Django projectXiaoqi Zhao
 
Django_3_Tutorial_and_CRUD_Example_with.pdf
Django_3_Tutorial_and_CRUD_Example_with.pdfDjango_3_Tutorial_and_CRUD_Example_with.pdf
Django_3_Tutorial_and_CRUD_Example_with.pdfDamien Raczy
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJames Casey
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineYared Ayalew
 

Semelhante a Mini Curso de Django (20)

Mini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesMini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico Ces
 
Django web framework
Django web frameworkDjango web framework
Django web framework
 
An Introduction to Django Web Framework
An Introduction to Django Web FrameworkAn Introduction to Django Web Framework
An Introduction to Django Web Framework
 
Django
DjangoDjango
Django
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
React django
React djangoReact django
React django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
DJango
DJangoDJango
DJango
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Virtual Environment and Web development using Django
Virtual Environment and Web development using DjangoVirtual Environment and Web development using Django
Virtual Environment and Web development using Django
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for Beginners
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheet
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to django
 
Build and deploy Python Django project
Build and deploy Python Django projectBuild and deploy Python Django project
Build and deploy Python Django project
 
Django_3_Tutorial_and_CRUD_Example_with.pdf
Django_3_Tutorial_and_CRUD_Example_with.pdfDjango_3_Tutorial_and_CRUD_Example_with.pdf
Django_3_Tutorial_and_CRUD_Example_with.pdf
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 

Mini Curso de Django

  • 1. Welcome to the Django!
  • 2. 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."
  • 3. Origins... Django Reinhardt
  • 4. Origins... Lawrence-Journal World
  • 5. Origins... Pycon 2005 - Adrian Holovaty e Simon Willison BSD License* Django Software Foundation - 2008 * http://en.wikipedia.org/wiki/BSD_licenses
  • 7. Skills Convention Over Configuration Object-Relational Mapping (ORM) Very useful admin CRUD Form handling Elegant URL Design Template system Cache system i18n
  • 8. Principles (...or philosophies) DRY (Don't Repeat Yourself ) Loose coupling Write less code as possible Quick development Explicit is better than implicit
  • 11. MVC vs. MTV Model --> Model View --> Template Controller --> View
  • 13. Go to the Project!
  • 14. Setting up... Download djangoproject.com/download Install Unzip Django-x.x.tar.gz python setup.py install Or... apt-get install python-django (Debian like OS)
  • 15. Create a Project... django-admin.py startproject my_project
  • 16. Setup files __init__.py - indicates a python package manager.py - admin tasks settings.py - project settings urls.py - project urls map
  • 17. 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... "
  • 18. Development server python manager.py syncdb python manager.py runserver [8000]
  • 19. Others Servers... Development Server Apache + Mod_Python Apache + FastCGI
  • 20. Create the app python manage.py startapp my_blog
  • 21. Setup files init.py - indicates a python package models.py - app domain model views.py - project controller
  • 22. 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
  • 23. 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()
  • 24. Setting the model classes to admin Open admin.py and edit: from django.contrib import admin from models import Artigo admin.site.register(Artigo)
  • 25. Add the app to the admin Open settings.py and add: "my_project.blog" Re-sync the database Re-run the development server
  • 26. 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 admin admin.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), )
  • 27. 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>
  • 28. Look your app! http://localhost:8000/
  • 29. Recap... Django is easy Django is fun Django scales Django is maintainable Django saves small kittens It rocks - USE IT!
  • 30. Sites powered by Python/Django
  • 31.
  • 32. Contact/follow us... leofernandesmo@gmail.com felipe.buarque@gmail.com Twitter: @leofernandesmo @felipe_wally