SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
A Quick Overview
A bit about me

•   Programmer @ 5Q Communications
•   Hack on Django mostly full-time
•   Dozen+ sites in production
•   Calvin grad
A bit about Django

•   Named after Django Reinhart, jazz guitarist
•   Python 2.3+ (Not 3.x yet, afiak)
•   BSD license
•   djangoproject.com
•   Current release: 1.1
Who uses it?
•   NASA
•   PBS
•   NY Times
•   LA Times
•   National Geographic
•   Discovery Channel
Features

•   Object-Relational     •   i18n/unicode support
    Mapper
                          •   Cache framework
•   MVC architecture
                          •   Testing framework
•   Templating Language
                          •   Great docs (650+ pages)
•   “Automatic” admins
                          •   Friendly community
•   Elegant urls
More Features

•   Jython support        •   Built-in RSS/ATOM
•   Geospacial content    •   Built-in site maps
    (via GeoDjango)
                          •   Send emails easily
•   Built-in dev server
                          •   “Signal” hooks
•   Nice support
                          •   Solid security emphasis
    for forms
Projects and Apps
Settings: database,               App   Live anywhere in your
email, caching, etc.   Project          PYTHONPATH
                                  App


      HTML, CSS,                  App
      images, etc. Templates
                       & Assets   App
Typical Project Layout
       project/
         __init__.py
         settings.py
         manage.py
         urls.py
         templates/
         static/
         staff_members/
            __init__.py
            models.py
            admin.py
            views.py
            urls.py
            tests.py
            templates/
Typical App Workflow

1. Create app
2. Create models.py and admin.py
3. ‘python manage.py syncdb’
4. Create urls.py and views.py
class StaffMemberGroup(models.Model):
   name = models.CharField(blank=True, max_length=100)
   order = models.IntegerField(blank=True, null=True)

class StaffMember(models.Model):
   first_name = models.CharField(max_length=100)
   last_name = models.CharField(max_length=100)
   title = models.CharField(blank=True, max_length=100)
   bio = models.TextField(blank=True)
   image = models.FileField(upload_to='bio_images', blank=True)
   email = models.EmailField()
   published = models.BooleanField()
   staff_group = models.ForeignKey(StaffMemberGroup)
python manage.py syncdb

1. Create tables
2. Create basic indexes
3. Create intermediate tables
   for m2m relationships
bob = StaffMember(first_name=”Bob”, last_name=”Smith”)

members = StaffMember.objects.all()

ordered_members =
 StaffMember.objects.all().order_by(‘last_name’)

published_members =
 StaffMember.objects.filter(published=True)
groups = StaffMemberGroup.objects.all()

for group in groups:
  print group.name
    for member in group.staffmember_set.all():
       print member.first_name
class StaffMemberAdmin(admin.ModelAdmin):
   list_display = ('last_name', 'first_name', 'email', 'published')
   list_filter = ('published', 'staff_group')
   search_fields = ('first_name', 'last_name', 'bio', 'title', 'email')
   fieldsets = (
       (None, {
           'fields': (('first_name', 'last_name'), 'title', 'email', 'image', 'bio'),
           'description': '',
       }),
       ('Options', {
           'fields': ('published', 'staff_group'),
       })
   )
admin.site.register(StaffMember, StaffMemberAdmin)
project urls.py
urlpatterns = patterns('',
   (r'^staff_members/', include('grpug.staff_members.urls')),
   (r'^admin/doc/', include('django.contrib.admindocs.urls')),
   (r'^admin/(.*)', admin.site.root),
)


staff_members app urls.py:
urlpatterns = patterns('grpug.staff_members.views',
   url(r'^$', 'show_staff_members', name='staff-members'),
)
def show_staff_members(request):
  groups = StaffMemberGroup.objects.all()
  return render_to_response(
     'staff_member.html',
     {'groups': groups}
  )
staff_member.html
{% for group in groups %}
  <h2>{{group.name}}</h2>
  <ul>
     {% for member in group.staffmember_set.all %}
        <li>
        <h3>{{member.first_name}} {{member.last_name}}</h3>
        <p>{{member.bio}}</p>
        </li>
     {% endfor %}
  </ul>
{% endfor %}
staff_member.html
{% extends ‘base_site.html’ %}

  {% block content %}
  {% for group in groups %}
    <h2>{{group.name}}</h2>
    <ul>
       {% for member in group.staffmember_set.all %}
          <li>
          <h3>{{member.first_name}} {{member.last_name}}</h3>
          <p>{{member.bio}}</p>
          </li>
       {% endfor %}
    </ul>
  {% endfor %}
{% endblock content %}
base_site.html
  <html>
  <body>
    {% block content %}
    {% endblock content %}
  </body>
  </html>
Middleware

•   process_request(self, request)
•   process_view(self, request, view_func,
      view_args, view_kwargs)
•   process_response(self, request, response)
•   process_exception(self, request, exception)
Testing Framework

•   doctests
•   unit tests
•   helpful stuff: fixtures, email test, “client”

    c = Client()
    response = c.post(‘/login’, user_dict)
Some Warts
•   No support for           •   REST/SOAP
    multiple databases           support lacking
•   Poor environment         •   “Explicit” but still tightly
    support (think rails)        coupled for some things
•   Template logic tags      •   No integrated
    below average                deployment toolchain
•   No built-in migrations   •   CMS extras lacking
                                 (wysiwyg, file browser...)
•   Too big?
Rest of the stack

•   Databases        •       Deployment
    •   SQLite           •    mod_python
    •   MySQL            •    mod_wsgi
    •   Postgresql       •    fast cgi
    •   Oracle
Tips
•   virtualenv is your friend
•   default settings.py is about 50% of what a
    production site ends up requiring
•   local_settings.py
•   Don’t be afraid of lots of apps
•   ‘South’ is a solid migrations tool
Docs, Books, People

•   docs.djangoproject.com
•   djangobook.com
•   djangosnippets.com
•   djangopeople.net
•   djangosites.org
Code Samples


•   http://bitbucket.org/btol45/grpug-example/

Contenu connexe

Tendances

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Djangocolinkingswood
 
The Django Book - Chapter 5: Models
The Django Book - Chapter 5: ModelsThe Django Book - Chapter 5: Models
The Django Book - Chapter 5: ModelsSharon Chen
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using DjangoNathan Eror
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Djangofool2nd
 
Making Django and NoSQL Play Nice
Making Django and NoSQL Play NiceMaking Django and NoSQL Play Nice
Making Django and NoSQL Play NiceAlex Gaynor
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 
A gentle intro to the Django Framework
A gentle intro to the Django FrameworkA gentle intro to the Django Framework
A gentle intro to the Django FrameworkRicardo Soares
 
Intro to Web Development Using Python and Django
Intro to Web Development Using Python and DjangoIntro to Web Development Using Python and Django
Intro to Web Development Using Python and DjangoChariza Pladin
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Eric Palakovich Carr
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of DjangoJacob Kaplan-Moss
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + djangoNina Zakharenko
 
Google App Engine with Gaelyk
Google App Engine with GaelykGoogle App Engine with Gaelyk
Google App Engine with GaelykChoong Ping Teo
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST FrameworkLoad Impact
 
Django and Mongoengine
Django and MongoengineDjango and Mongoengine
Django and Mongoengineaustinpublic
 

Tendances (20)

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Tango with django
Tango with djangoTango with django
Tango with django
 
The Django Book - Chapter 5: Models
The Django Book - Chapter 5: ModelsThe Django Book - Chapter 5: Models
The Django Book - Chapter 5: Models
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
Making Django and NoSQL Play Nice
Making Django and NoSQL Play NiceMaking Django and NoSQL Play Nice
Making Django and NoSQL Play Nice
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
Django
DjangoDjango
Django
 
Django a whirlwind tour
Django   a whirlwind tourDjango   a whirlwind tour
Django a whirlwind tour
 
A gentle intro to the Django Framework
A gentle intro to the Django FrameworkA gentle intro to the Django Framework
A gentle intro to the Django Framework
 
Intro to Web Development Using Python and Django
Intro to Web Development Using Python and DjangoIntro to Web Development Using Python and Django
Intro to Web Development Using Python and Django
 
Selenium&amp;scrapy
Selenium&amp;scrapySelenium&amp;scrapy
Selenium&amp;scrapy
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + django
 
Google App Engine with Gaelyk
Google App Engine with GaelykGoogle App Engine with Gaelyk
Google App Engine with Gaelyk
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST Framework
 
Django and Mongoengine
Django and MongoengineDjango and Mongoengine
Django and Mongoengine
 
Django Mongodb Engine
Django Mongodb EngineDjango Mongodb Engine
Django Mongodb Engine
 
Geotalk presentation
Geotalk presentationGeotalk presentation
Geotalk presentation
 

En vedette

Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Djangoryates
 
Getting Started With Django
Getting Started With DjangoGetting Started With Django
Getting Started With Djangojeff_croft
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2fishwarter
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for BeginnersJason Davies
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best PracticesDavid Arcos
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonNowell Strite
 

En vedette (12)

Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Django
 
Free django
Free djangoFree django
Free django
 
Getting Started With Django
Getting Started With DjangoGetting Started With Django
Getting Started With Django
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
Django introduction
Django introductionDjango introduction
Django introduction
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for Beginners
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best Practices
 
Django Best Practices
Django Best PracticesDjango Best Practices
Django Best Practices
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 

Similaire à Django Overview

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
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)Doris Chen
 
國民雲端架構 Django + GAE
國民雲端架構 Django + GAE國民雲端架構 Django + GAE
國民雲端架構 Django + GAEWinston Chen
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTTkevinvw
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPOscar Merida
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildwebLeo Zhou
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoFu Cheng
 
BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsBackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsJoseph Khan
 
Python - A Comprehensive Programming Language
Python - A Comprehensive Programming LanguagePython - A Comprehensive Programming Language
Python - A Comprehensive Programming LanguageTsungWei Hu
 
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Lucidworks
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to TornadoGavin Roy
 
Django introduction @ UGent
Django introduction @ UGentDjango introduction @ UGent
Django introduction @ UGentkevinvw
 
Spring 3 - An Introduction
Spring 3 - An IntroductionSpring 3 - An Introduction
Spring 3 - An IntroductionThorsten Kamann
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your WebsiteAcquia
 
Open Social In The Enterprise
Open Social In The EnterpriseOpen Social In The Enterprise
Open Social In The EnterpriseTim Moore
 
12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocratlinoj
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Derek Jacoby
 

Similaire à Django Overview (20)

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
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
國民雲端架構 Django + GAE
國民雲端架構 Django + GAE國民雲端架構 Django + GAE
國民雲端架構 Django + GAE
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTT
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 
JS Essence
JS EssenceJS Essence
JS Essence
 
BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsBackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applications
 
Python - A Comprehensive Programming Language
Python - A Comprehensive Programming LanguagePython - A Comprehensive Programming Language
Python - A Comprehensive Programming Language
 
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
Django introduction @ UGent
Django introduction @ UGentDjango introduction @ UGent
Django introduction @ UGent
 
Spring 3 - An Introduction
Spring 3 - An IntroductionSpring 3 - An Introduction
Spring 3 - An Introduction
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your Website
 
Open Social In The Enterprise
Open Social In The EnterpriseOpen Social In The Enterprise
Open Social In The Enterprise
 
12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat
 
Introduction to Monsoon PHP framework
Introduction to Monsoon PHP frameworkIntroduction to Monsoon PHP framework
Introduction to Monsoon PHP framework
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9
 

Dernier

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Dernier (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

Django Overview

  • 2. A bit about me • Programmer @ 5Q Communications • Hack on Django mostly full-time • Dozen+ sites in production • Calvin grad
  • 3.
  • 4. A bit about Django • Named after Django Reinhart, jazz guitarist • Python 2.3+ (Not 3.x yet, afiak) • BSD license • djangoproject.com • Current release: 1.1
  • 5.
  • 6. Who uses it? • NASA • PBS • NY Times • LA Times • National Geographic • Discovery Channel
  • 7. Features • Object-Relational • i18n/unicode support Mapper • Cache framework • MVC architecture • Testing framework • Templating Language • Great docs (650+ pages) • “Automatic” admins • Friendly community • Elegant urls
  • 8. More Features • Jython support • Built-in RSS/ATOM • Geospacial content • Built-in site maps (via GeoDjango) • Send emails easily • Built-in dev server • “Signal” hooks • Nice support • Solid security emphasis for forms
  • 9. Projects and Apps Settings: database, App Live anywhere in your email, caching, etc. Project PYTHONPATH App HTML, CSS, App images, etc. Templates & Assets App
  • 10. Typical Project Layout project/ __init__.py settings.py manage.py urls.py templates/ static/ staff_members/ __init__.py models.py admin.py views.py urls.py tests.py templates/
  • 11. Typical App Workflow 1. Create app 2. Create models.py and admin.py 3. ‘python manage.py syncdb’ 4. Create urls.py and views.py
  • 12. class StaffMemberGroup(models.Model): name = models.CharField(blank=True, max_length=100) order = models.IntegerField(blank=True, null=True) class StaffMember(models.Model): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) title = models.CharField(blank=True, max_length=100) bio = models.TextField(blank=True) image = models.FileField(upload_to='bio_images', blank=True) email = models.EmailField() published = models.BooleanField() staff_group = models.ForeignKey(StaffMemberGroup)
  • 13. python manage.py syncdb 1. Create tables 2. Create basic indexes 3. Create intermediate tables for m2m relationships
  • 14. bob = StaffMember(first_name=”Bob”, last_name=”Smith”) members = StaffMember.objects.all() ordered_members = StaffMember.objects.all().order_by(‘last_name’) published_members = StaffMember.objects.filter(published=True)
  • 15. groups = StaffMemberGroup.objects.all() for group in groups: print group.name for member in group.staffmember_set.all(): print member.first_name
  • 16. class StaffMemberAdmin(admin.ModelAdmin): list_display = ('last_name', 'first_name', 'email', 'published') list_filter = ('published', 'staff_group') search_fields = ('first_name', 'last_name', 'bio', 'title', 'email') fieldsets = ( (None, { 'fields': (('first_name', 'last_name'), 'title', 'email', 'image', 'bio'), 'description': '', }), ('Options', { 'fields': ('published', 'staff_group'), }) ) admin.site.register(StaffMember, StaffMemberAdmin)
  • 17.
  • 18.
  • 19.
  • 20. project urls.py urlpatterns = patterns('', (r'^staff_members/', include('grpug.staff_members.urls')), (r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^admin/(.*)', admin.site.root), ) staff_members app urls.py: urlpatterns = patterns('grpug.staff_members.views', url(r'^$', 'show_staff_members', name='staff-members'), )
  • 21. def show_staff_members(request): groups = StaffMemberGroup.objects.all() return render_to_response( 'staff_member.html', {'groups': groups} )
  • 22. staff_member.html {% for group in groups %} <h2>{{group.name}}</h2> <ul> {% for member in group.staffmember_set.all %} <li> <h3>{{member.first_name}} {{member.last_name}}</h3> <p>{{member.bio}}</p> </li> {% endfor %} </ul> {% endfor %}
  • 23. staff_member.html {% extends ‘base_site.html’ %} {% block content %} {% for group in groups %} <h2>{{group.name}}</h2> <ul> {% for member in group.staffmember_set.all %} <li> <h3>{{member.first_name}} {{member.last_name}}</h3> <p>{{member.bio}}</p> </li> {% endfor %} </ul> {% endfor %} {% endblock content %}
  • 24. base_site.html <html> <body> {% block content %} {% endblock content %} </body> </html>
  • 25. Middleware • process_request(self, request) • process_view(self, request, view_func, view_args, view_kwargs) • process_response(self, request, response) • process_exception(self, request, exception)
  • 26. Testing Framework • doctests • unit tests • helpful stuff: fixtures, email test, “client” c = Client() response = c.post(‘/login’, user_dict)
  • 27. Some Warts • No support for • REST/SOAP multiple databases support lacking • Poor environment • “Explicit” but still tightly support (think rails) coupled for some things • Template logic tags • No integrated below average deployment toolchain • No built-in migrations • CMS extras lacking (wysiwyg, file browser...) • Too big?
  • 28. Rest of the stack • Databases • Deployment • SQLite • mod_python • MySQL • mod_wsgi • Postgresql • fast cgi • Oracle
  • 29. Tips • virtualenv is your friend • default settings.py is about 50% of what a production site ends up requiring • local_settings.py • Don’t be afraid of lots of apps • ‘South’ is a solid migrations tool
  • 30. Docs, Books, People • docs.djangoproject.com • djangobook.com • djangosnippets.com • djangopeople.net • djangosites.org
  • 31. Code Samples • http://bitbucket.org/btol45/grpug-example/