django

15
Django is a high-level Python Web framework that encourages rapid development, pragmatic design and follows DRY principles. By Abhijeet Shekhar Blog: http://ashekhar.wordpress.com

Upload: abhijeet-shekhar

Post on 21-May-2015

675 views

Category:

Software


2 download

DESCRIPTION

Django is a high-level Python Web framework that encourages rapid development, pragmatic design and follows DRY principles.

TRANSCRIPT

Page 1: Django

Django is a high-level Python Web framework that encourages rapid development, pragmatic design and follows DRY principles.

By Abhijeet ShekharBlog: http://ashekhar.wordpress.com

Page 2: Django

Features• Legacy DB• Test Framework• Multi- DB• Geodjango• Aggregation• JSON Serializer• Stable API Promise• Fantastic Docs

• Generic View• Template Inheritance• Template Filters• Humanize• Runs on Jython /Iron

Python• Google App Engine

Page 3: Django

Architecture

Page 4: Django

Component Architecture

Page 5: Django

Django is MTV/MVP framework

-Model (app/models.py-Template ( app/templates/*.html)-View (app/view.py)

Page 6: Django

Project Structure

-project= the full website app=python library

-Sample--__init__.py--settings.py--urls.py--wsgi.py-app-1--_init_.py--admin.py--models.py

--tests.py--urls.py--view.py-app-2

template/manage.pyenv/readme

Page 7: Django

Environment setup and installationStandard installation:• Content will be stored in the default location of

pythonVirtual installation:• All dependent library can be installed in the virtual

environment.• one project will be one virtualenv.• Every project with different dependencies in terms

of libraries and version.• Easier to deploy and forget dependency• Virtualenvwrapper is a convenient

Page 8: Django

Steps to create a project• Create a project• Start an application• Create your database(Mysql, Post gre)• Configure DB settings in settings.py• Define your models• Add external modules• Add your template• Write your view• Create url mappping• Test application• Deploy application (linux apache , mod

python

Page 9: Django

$ django-admin.py startproject <project_name>$ cd <project_name>$ Python manage.py startapp my$ edit settings.py and set DB info$ python manage.py runserverBrowse http://localhost:8000

Initialize Your Project

Page 10: Django

Settings:

-multiple setting files:-per environment: dev, testing, staging , Production Per developer (local settings, use the host name )

-all setting file must inherit from , so you can doINSTALLED_APPS +=(‘debug_toolbar’)-version control all the setting !

Page 11: Django

Fat models, thin viewer…

-multiple setting files:-per environment: dev, testing, staging , productionPer developer (local settings, use the host name )

-all setting file must inherit from , so you can doINSTALLED_APPS +=(‘debug_toolbar’)-version control all the setting !

Page 12: Django

Debugging

- ipython (./mange.py shell)- Ipdb- Import ipdb- Ipdb.set_trace()- django-debug-toolbar- very powerful- use it to optimze db performance, view by view

Page 13: Django

Migration

- South/migrate: - Intelligent schema & data migrations for Django- Can do backward migrations

Page 14: Django

Deployment

Web server- Niginx/Apache- wsgi- mod_python

Static server- Nginx or any CDN

Page 15: Django

Thanks