Your SlideShare is downloading. ×
0
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Django tech-talk
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Django tech-talk

483

Published on

Simple overview of the Django Web Framework mainly discussing the MVC pattern and templates.

Simple overview of the Django Web Framework mainly discussing the MVC pattern and templates.

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
483
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Tech Talk: Django A Brief Overview and Examples Dustin Dannenhauer dtdannen @ indiana.edu March 22nd, 2011
  • 2. What is Django?
    • Development tool that makes building websites easier
    • 3. Written in Python
    • 4. DRY (Don't Repeat Yourself)
    • 5. Originally designed for news websites
  • 6. Current sites using Django
    • bitbucket.org
    • 7. guardian.co.uk (~2.5 million hits a month)
    • 8. giantbomb.com
    • 9. newyorktimes.com
    • 10. comicvine.com
    • 11. washingtonpost.com
    • 12. lawrence.com
  • 13. Why use a web framework?
    • Make things easier
      • Database ORM's
      • 14. Automatic Admin Web Interface
      • 15. Elegant URL design
    • Remove Redundancy
      • Template System (don't want to copy html around like headers, footers, etc)
      • 16. Model-View-Controller architectural pattern (MVC)
  • 17. Model-View-Controller(MVC)
    • Model = Database
    • 18. View = User Interface
    • 19. Controller = Handles Input/Output
  • 20. Model = Database ORM
    • Object Relational Mapper (ORM)
    • 21. Instead of writing SQL statements to interact with the database, use objects (classes) in python to interact with relational database
  • 22. Model Details
    • Transfer data between the objects (Python classes) and the relational database
    • 23. Each Python class represents a table in the database, each actual object is a row
    • 24. Python classes defined in file: models.py
    • 25. All fields of a class represent a field in the database
    • 26. You can add your own methods on top to supplement fields
  • 27. Example: models.py from django.db import models class Reporter(models.Model): full_name = models.CharField(max_length=70) class Article(models.Model): pub_date = models.DateTimeField() headline = models.CharField(max_length=200) content = models.TextField() reporter = models.ForeignKey(Reporter)
  • 28. Using classes in models.py >>> Reporter.objects.all() [] # Create a new Reporter. >>> r = Reporter(full_name='John Smith') # Save the object into the database. You have to call save() explicitly. >>> r.save() # Now it has an ID. >>> r.id 1 # Now the new reporter is in the database. >>> Reporter.objects.all() [<Reporter: John Smith>]
  • 29. View
    • Python functions that are called when a user goes to a specific url
      • Ex: www.site.com/login calls the view mapped to login
    • Every URL is mapped to a view
    • 30. Code is written in file: views.py
  • 31. Urls
    • Every URL has a corresponding view
    • 32. Data from the URL can be passed into the view
    • 33. Uses regular expressions to match the URL to what the user tried to go to
  • 34. Elegant Urls
    • When a user visits a url, the connected view is called with any data from the url
    • 35. urlpatterns = patterns('',
    • 36. (r'^articles/(d{4})$','news.views.year_archive'),
    • 37. (r'^articles/(d{4})/(d{2})/$',
    • 38. 'news.views.month_archive'),
    • 39. (r'^articles/(d{4})/(d{2})/(d+)/$',
      • 'news.views.article_detail'),
    • )
  • 40. Example: views.py def year_archive(request, year): a_list = Article.objects.filter(pub_date__year=year) return render_to_response( 'news/year_archive.html', {'year': year, 'article_list': a_list})
  • 41. Templates
    • The result of a view function is ”roughly” the html page returned to the user
    • 42. Variables can be passed into a template
    • 43. Template Inheritance
  • 44. Example Base Template <html> <head> <title>{% block title %}{% endblock %}</title> </head> <body> <img src=&quot;sitelogo.gif&quot; alt=&quot;Logo&quot; /> {% block content %}{% endblock %} </body> </html>
  • 45. Example Child Template {% extends &quot;base.html&quot; %} {% block title %}Articles for {{ year }}{% endblock %} {% block content %} <h1>Articles for {{ year }}</h1> {% for article in article_list %} <p>{{ article.headline }}</p> <p>By {{ article.reporter.full_name }}</p> <p>Published {{ article.pub_date|date:&quot;F j, Y&quot; }}</p> {% endfor %} {% endblock %}
  • 46. Not Mentioned
    • Caching Framework
    • 47. Syndication Framework (RSS and Atom Feeds)
    • 48. Modularity of Django (many little apps)
    • 49. Deployment
    • 50. and much more...
  • 51. More Resources
    • http://www.djangoproject.com/
    • 52. http://www.djangobook.com/
    • 53. Presentation on ”High Performance Django”
    • 54. http://www.slideshare.net/zeeg/django-con-high-performance-django-presentation

×