django - computer science · named after guitarist django reinhardt in 2008 django software...

16
Django Open Data NC Bo Warren Ben Parisi Austin Schneider Brian Bollerman

Upload: votuyen

Post on 05-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

DjangoOpen Data NC Bo Warren Ben Parisi Austin Schneider Brian Bollerman

Page 2: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

About● free and opensource web framework

○ BSD licenced● written in python

○ supports any platform that python supports● purpose: ease creation of database driven, complex websites

○ covers most aspects of web development (databases, views, controllers)

● Follows Don’t repeat yourself Principle○ “Every piece of knowledge must have a single, unambiguous,

authoritative representation within a system.”○ - The Pragmatic Programmer○ synchronized changes

Page 3: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

History● began in 2003 at Lawrence Journal-World newspaper, Kansas

○ to help web developers create websites efficiently within a limited time period

● Initial release: 2005● named after guitarist Django Reinhardt● In 2008 Django Software Foundation founded and received 501(c)(3) non-

profit status○ gives out “awards” ○ foster community

Page 4: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

Motivation● What does it fix?

○ 2 challenges:■ making data (stories, blog posts, etc) look presentable and

consistent■ intensive deadlines of a newsroom

○ writing straight html/css/javascript/php/sql■ lots of time■ complicated■ learning curve

Page 5: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

Structure of the Framework

Source: http://www.erikmitchell.info/2010/09/28/using-django-to-create-complex-sites-simply/

Page 6: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

URL Handling

•Idea: Create a python module that maps URL patterns (as

regular expressions) to Python functions (the desired views for

each URL)

Page 7: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

URL Handling

•Django uses file urls.py and looks for variable “urlpatterns”

which is of datatype list

•Django runs through each URL pattern in order and stops at the

first one that matches.

Page 8: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

URL Handling

•Once one of the regular expressions matches, Django imports

and calls the chosen view, which is a Python function, and passes

it an instance of an HttpRequest class (created by Django), as

well as the matched parts of the regular expression

Page 9: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

Structure of the Framework

Structure of the Framework

Page 10: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

View

● When a regular expression is matched in urls.py○ a function in views.py is

called.● The function returns a render

of an html page or a 404.

Page 11: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

Templates● Text documents or python strings that are marked-up using

Django Template Language to generate text-based formats (HTML, XML, CSV, etc.)○ Block tags:

■ {% if is_logged_in %} logged in? {% else %} login {% endif %}

○ Variables:■ My dog’s name is {{ dogs_name }}.

Page 12: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

Templates cont.

Page 13: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

Templates cont.

Page 14: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

Database Interaction● supported dbs

○ postgreSQL, mySQL, Sqlite, Oracle● doesn’t support non-relational

○ e.g. mongoDB● little/no sql needs to be written by developer● why no sql?

○ streamline● tables are python classes

○ used as an api, much easier○ to interact with db, all you have to do is import the classes

■ create new objects of type class, set and interact w/ standard methods

Page 15: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

Demo: ● Create, Populate, & Query a DB

Page 16: Django - Computer Science · named after guitarist Django Reinhardt In 2008 Django Software Foundation founded and received 501(c)(3) non-profit status gives out “awards”

Sites using Django● https://www.pinterest.com/

● http://www.theonion.com/

● http://instagram.com/

● https://disqus.com/