26
Django Framework The web framework for perfectionists with deadlines Rosario Renga [email protected]

Django Framework Overview forNon-Python Developers

Embed Size (px)

Citation preview

Django FrameworkThe web framework for perfectionists with deadlines

Rosario Renga [email protected]

1. What is Django

2. What is Python

3. Django’s Capabilities

a. All-in-One and Ready to Use

b. Modularity

c. Pattern: MTV and DRY

d. Deployment strategies

4. Useful Links

Summary

› Django is a high-level Python Web framework.

› Rapid development and clean, pragmatic design.

› Focus on writing your app without needing to

reinvent the wheel.

› It’s free and open source.

From https://www.djangoproject.com/

What is Django ?

Instagram: http://instagram.com/

Pinterest: https://www.pinterest.com/

The Washington Post:

http://www.washingtonpost.com/

Mozilla’s blog:

http://blog.mozilla.org/webdev/

My blog! http://blog.itsmurfs.it/

Who use Django ?

Enterprise Point Of View

Free and Open-source.

Thousand of free reusable apps already pluggable

into one’s project.

Compatible with all the main databases.

Compatible with all the JS and CSS Frameworks.

Why Django ?

Developer Point Of View

Use and learn a new language: Python.

DB Management and ORM built-in.

Rich documentation.

Active community.

Modular architecture.

DRY Principle (Don’t Repeat Yourself).

MVC Pattern reinterpreted in MTV.

Why DJAngo ?

Questions?

What is Django ?

Python is an interpreted, interactive, object-oriented

programming language.

Platform indipendent.

Combines remarkable power with very clear syntax.

Very rich community and many libraries and

frameworks.

It’s free and open source.

What is python ?

Open google and search for: most used programming

languages 2014

Who use Python?

Syntax:

No “;” and “{ }”

Blocks starts with “:” and are identified by Indentation

No statically typed. You don’t need to declare any variable

You can mix object-oriented and imperative programming.

What is python ?

What is python ?

What is python ?

List:

Declared using “[ ]”

Access using index

Mutable

Tuple:

Declared using “( )”

Access using index

Immutable Dictionary:

Declared using “ { } “ Access using keyword

Data Structure:

What is python ?

Easy to install:

Download and Install Python:

https://www.python.org/downloads/

Install pip ( https://bootstrap.pypa.io/get-pip.py ):

Install Django

Django’s Capabilities

python get-pip.py

pip install django

› Don’t worry there is an IDE that can do these dirties things for you:

› Or you can use Eclipse with pyDev (http://pydev.org/ )

› Ready to use:

To start a new project just type in a cmd:

Then starts a new app with:

Django’s Capabilities

django-admin.py startproject mysite

python manage.py startapp polls

Let’s look at the structure the commands have

created:

Django’s Capabilities

Project root

Project package

App package

Project configurations files

Application files

All in one:› With these two commands we have:

Created the project structure

Installed the ORM

Installed a development server

Installed and configured an SQLite database

Installed the admin interface

Installed a ready to use unit-test environement

Django’s Capabilities

– Create the database tables based on the models found in the installed apps.

– Create the database for the authentication system included in django

– Create a superuser account for the authentication system

– Set up a system for propagating change makes to the models into the database

schema

python manage.py migrate

Modularity: You can take existing Python packages or Django apps and compose

them into your own web project. You only need to write the parts that

make your project unique.

Built-in reusable apps:

django.contrib.admin – The admin site.

django.contrib.auth – An authentication system.

django.contrib.contenttypes – A framework for content types.

django.contrib.sessions – A session framework.

django.contrib.messages – A messaging framework.

django.contrib.staticfiles – A framework for managing static files.

Django’s Capabilities

Third party reusable apps: Django REST framework is a framework to build REST APIs.

Celery is the standard to manage asynchronous, distributed job queues.

Django mailer provides a backend for sending email

django-allauth allows for both local and social authentication

django-grappelli A jazzy skin for the Django Admin-Interface

django-tables2 An app for creating HTML tables

django-dajax Easy to use library to create asynchronous presentation logic with django

And much more….

Django’s Capabilities

› All these apps can be installed simply typing:

pip install <app_name>

How to write reusable apps:

The app we have just created is already reusable!

Just copy and paste it to another project and link it in the settings.py

Of course there is a more complete way to package an app:

https://docs.djangoproject.com/en/1.7/intro/reusable-apps/#packaging-yo

ur-app

How to find more apps:

Check https://www.djangopackages.com/ a directory of reusable apps, sites,

tools, and more for your Django projects

Ask to the community: https://groups.google.com/forum/#!forum/django-it

Try to search them: www.google.com

Django’s Capabilities

DRY (Don’t Repeat Yourself)

The DRY principal was one of the fundamental concepts that Django was designed around.

The DRY principal is all about keeping code simple and non repeating. This allows developers to reuse code they wrote for one project in another project.

To help developers adhere to the DRY principle, Django forces users to use the MVC by initially creating a standard project structure.

Django’s Capabilities

A different interpretation of the MVC: MTV: Model View Template

In django interpretation of MVC, the “view” describes the data that gets presented to the user. It’s not necessarily how the data looks, but which data is presented. The view describes which data you see, not how you see it.

Furthermore, it’s sensible to separate content from presentation – which is where templates come in. In Django, a “view” describes which data is presented, but a view normally delegates to a template, which describes how the data is presented.

Django’s Capabilities

Deployment Strategies:

In the cloud:

Heroku

Google Appengine

On a remote machine:

NGINX + uWSGI or Gunicorn

Apache + mod_wsgi

Django’s Capabilities

Official site: https://www.djangoproject.com/

Official google groups:

https://groups.google.com/forum/#!forum/django-users

Italian community: https://groups.google.com/forum/#!forum/django-it

Snippets of reusable code: https://djangosnippets.org/

Collection of useful links: http://www.fullstackpython.com/django.html

Useful links

› Learning sites:

– https://docs.djangoproject.com/en/1.7/intro/

– http://www.tangowithdjango.com/

– http://tutorial.djangogirls.org/en/index.html

– http://effectivedjango.com/tutorial/

– http://www.djangobook.com/en/2.0/index.html

– http://stacktrace.it/site_media/luambo/uploads/2009/09/14/Copia_visione_Django.pdf

Questions?

Thanks.