Django is a high-level Python web framework that encourages rapid development. It follows a MTV/MVP architecture with models, templates, and views. It has features like legacy database support, test frameworks, and JSON serialization. Django projects have a modular structure with reusable apps, settings files, URLs, and WSGI configuration.
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
Django
1. 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
2. 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
7. Environment setup and installation
Standard installation:
• Content will be stored in the default location of
python
Virtual 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
8. 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
9. Initialize Your Project
$ django-admin.py startproject <project_name>
$ cd <project_name>
$ Python manage.py startapp my
$ edit settings.py and set DB info
$ python manage.py runserver
Browse http://localhost:8000
10. 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 do
INSTALLED_APPS +=(‘debug_toolbar’)
-version control all the setting !
11. Fat models, thin viewer…
-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 do
INSTALLED_APPS +=(‘debug_toolbar’)
-version control all the setting !
12. 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
13. Migration
- South/migrate:
- Intelligent schema & data migrations for
Django
- Can do backward migrations
14. Deployment
Web server
- Niginx/Apache
- wsgi
- mod_python
Static server
- Nginx or any CDN