SlideShare a Scribd company logo
1 of 12
Download to read offline
Introduction to Django
Django
"""The Web framework for perfectionists with
deadlines."""


"""Django is a high-level Python Web
framework that encourages rapid development
and clean, pragmatic design."""


                https://www.djangoproject.com/
What is inside?
● Built-in ORM(Object-relational Mapper)
● Simple but powerful URL system
● Built-in template system
● I10n(Internationalization)
● Cache system
● Built-in authentication system
● Built-in webserver(for development)
● Automatic admin interface
MVT not MVC
● Model
  ○ defines the data structure
  ○ takes care for querying the database
● View
  ○ defines what data should be presented
  ○ returns HTTP response
● Template
  ○ renders the data in suitable format - HTML/XML/etc.
The live of request
Project structure
To start new project run:
    django-admin.py startproject my_project
The following structure will be created

         my_project/
           manage.py
           my_project/
             __init__.py
             settings.py # project settings reside here
             urls.py
             wsgi.py

This is the default created and good for learning the basics but this way the
settings may be hard to maintain for project in production. Alternative approach
is available at http://ilian.i-n-i.org/django-project-file-structure/.
Application structure
To create new application in you project just run the following command
in the shell:
     python manage.py startapp app
The following structure will be created

    app/
      __init__.py
      admin.py # not created automatically before 1.5
      models.py
      tests.py
      views.py



There is no urls.py file but most developer find it useful to keep the application
specific URLs inside it and include them in the main URLs configuration file.
Models
# models.py
from django.db import models
from django.utils.translation import ugettext_lazy as _

class News(models.Model):
   title = models.CharField(_('Title'), max_length=255)
   slug = models.SlugField(_('Slug'))
   content = models.TextField()

To create the tables for the define models just run:
    python manage.py syncdb
URLs dispatcher
# urls.py
from django.conf.urls import patterns, url, include

urlpatterns = patterns('',
   url(r'^$', 'app.home', name='home'), # give the specific URL meaningful
name
   url(r'offers/', include('offers.urls')), # include URLs from another app
   (r'^news/$', 'news.views.offers'), # point to specific view
   (r'^news/(d{4})/$', 'news.views.year_archive'), # pass arg(s)
   (r'^news/(d{4})/(d{2})/$', 'news.views.month_archive'), # pass arg(s)
   (r'^news/(?P<slug>[-w]+)/$', 'news.views.single_news'), # pass named args
)

●   URLs dispatcher uses regular expression
●   The first match found is called
●   All arguments are passed as unicode strings
Views
# views.py
from .models import News
from django.shortcuts import get_object_or_404



def single_news(request, slug):
  news = get_object_or_404(News.objects.public(), slug=slug)
  return render_to_response('news/single_news.html', {'news': news})
Templates
# template.html

{% extends 'my_project/base.html' %}

<h1>{{ news.title }}</h1>
<div class="news-content">
     {{ news.content|safe }}
</div>
About Me
eng. Ilian Iliev

● Web Developer for 9+ years
● Python/Django fan for 3+ years
● ilian@i-n-i.org
● http://ilian.i-n-i.org
● https://github.com/IlianIliev/

More Related Content

What's hot

Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Edureka!
 
Web application development with Django framework
Web application development with Django frameworkWeb application development with Django framework
Web application development with Django frameworkflapiello
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture IntroductionHaiqi Chen
 
Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...Edureka!
 
Intro to Web Development Using Python and Django
Intro to Web Development Using Python and DjangoIntro to Web Development Using Python and Django
Intro to Web Development Using Python and DjangoChariza Pladin
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django IntroductionGanga Ram
 
Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Tom Brander
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2fishwarter
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best PracticesDavid Arcos
 
Django nutshell overview
Django nutshell overviewDjango nutshell overview
Django nutshell overviewschacki
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersRosario Renga
 
Django Templates
Django TemplatesDjango Templates
Django TemplatesWilly Liu
 

What's hot (20)

Django
DjangoDjango
Django
 
Django Girls Tutorial
Django Girls TutorialDjango Girls Tutorial
Django Girls Tutorial
 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...
 
Web application development with Django framework
Web application development with Django frameworkWeb application development with Django framework
Web application development with Django framework
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
django
djangodjango
django
 
Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...
 
Intro to Web Development Using Python and Django
Intro to Web Development Using Python and DjangoIntro to Web Development Using Python and Django
Intro to Web Development Using Python and Django
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Django, What is it, Why is it cool?
Django, What is it, Why is it cool?
 
Python/Django Training
Python/Django TrainingPython/Django Training
Python/Django Training
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best Practices
 
Django nutshell overview
Django nutshell overviewDjango nutshell overview
Django nutshell overview
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python Developers
 
Django Templates
Django TemplatesDjango Templates
Django Templates
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Django Seminar
Django SeminarDjango Seminar
Django Seminar
 

Similar to Introduction to django

Django framework
Django framework Django framework
Django framework TIB Academy
 
Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGiuliano Iacobelli
 
Rapid web application development using django - Part (1)
Rapid web application development using django - Part (1)Rapid web application development using django - Part (1)
Rapid web application development using django - Part (1)Nishant Soni
 
An Introduction to Django Web Framework
An Introduction to Django Web FrameworkAn Introduction to Django Web Framework
An Introduction to Django Web FrameworkDavid Gibbons
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030Kevin Wu
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineYared Ayalew
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheetLam Hoang
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim Rocha
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoAhmed Salama
 
Akash rajguru project report sem v
Akash rajguru project report sem vAkash rajguru project report sem v
Akash rajguru project report sem vAkash Rajguru
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting startedMoniaJ
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگوrailsbootcamp
 

Similar to Introduction to django (20)

Django framework
Django framework Django framework
Django framework
 
Why Django for Web Development
Why Django for Web DevelopmentWhy Django for Web Development
Why Django for Web Development
 
DJango
DJangoDJango
DJango
 
Django
DjangoDjango
Django
 
Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplications
 
Rapid web application development using django - Part (1)
Rapid web application development using django - Part (1)Rapid web application development using django - Part (1)
Rapid web application development using django - Part (1)
 
An Introduction to Django Web Framework
An Introduction to Django Web FrameworkAn Introduction to Django Web Framework
An Introduction to Django Web Framework
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Sahil_18118_IOT-ppt.pptx
Sahil_18118_IOT-ppt.pptxSahil_18118_IOT-ppt.pptx
Sahil_18118_IOT-ppt.pptx
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheet
 
Mini Curso de Django
Mini Curso de DjangoMini Curso de Django
Mini Curso de Django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
templates in Django material : Training available at Baabtra
templates in Django material : Training available at Baabtratemplates in Django material : Training available at Baabtra
templates in Django material : Training available at Baabtra
 
Django web framework
Django web frameworkDjango web framework
Django web framework
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Akash rajguru project report sem v
Akash rajguru project report sem vAkash rajguru project report sem v
Akash rajguru project report sem v
 
Basic Python Django
Basic Python DjangoBasic Python Django
Basic Python Django
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting started
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
 

Introduction to django

  • 2. Django """The Web framework for perfectionists with deadlines.""" """Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.""" https://www.djangoproject.com/
  • 3. What is inside? ● Built-in ORM(Object-relational Mapper) ● Simple but powerful URL system ● Built-in template system ● I10n(Internationalization) ● Cache system ● Built-in authentication system ● Built-in webserver(for development) ● Automatic admin interface
  • 4. MVT not MVC ● Model ○ defines the data structure ○ takes care for querying the database ● View ○ defines what data should be presented ○ returns HTTP response ● Template ○ renders the data in suitable format - HTML/XML/etc.
  • 5. The live of request
  • 6. Project structure To start new project run: django-admin.py startproject my_project The following structure will be created my_project/ manage.py my_project/ __init__.py settings.py # project settings reside here urls.py wsgi.py This is the default created and good for learning the basics but this way the settings may be hard to maintain for project in production. Alternative approach is available at http://ilian.i-n-i.org/django-project-file-structure/.
  • 7. Application structure To create new application in you project just run the following command in the shell: python manage.py startapp app The following structure will be created app/ __init__.py admin.py # not created automatically before 1.5 models.py tests.py views.py There is no urls.py file but most developer find it useful to keep the application specific URLs inside it and include them in the main URLs configuration file.
  • 8. Models # models.py from django.db import models from django.utils.translation import ugettext_lazy as _ class News(models.Model): title = models.CharField(_('Title'), max_length=255) slug = models.SlugField(_('Slug')) content = models.TextField() To create the tables for the define models just run: python manage.py syncdb
  • 9. URLs dispatcher # urls.py from django.conf.urls import patterns, url, include urlpatterns = patterns('', url(r'^$', 'app.home', name='home'), # give the specific URL meaningful name url(r'offers/', include('offers.urls')), # include URLs from another app (r'^news/$', 'news.views.offers'), # point to specific view (r'^news/(d{4})/$', 'news.views.year_archive'), # pass arg(s) (r'^news/(d{4})/(d{2})/$', 'news.views.month_archive'), # pass arg(s) (r'^news/(?P<slug>[-w]+)/$', 'news.views.single_news'), # pass named args ) ● URLs dispatcher uses regular expression ● The first match found is called ● All arguments are passed as unicode strings
  • 10. Views # views.py from .models import News from django.shortcuts import get_object_or_404 def single_news(request, slug): news = get_object_or_404(News.objects.public(), slug=slug) return render_to_response('news/single_news.html', {'news': news})
  • 11. Templates # template.html {% extends 'my_project/base.html' %} <h1>{{ news.title }}</h1> <div class="news-content"> {{ news.content|safe }} </div>
  • 12. About Me eng. Ilian Iliev ● Web Developer for 9+ years ● Python/Django fan for 3+ years ● ilian@i-n-i.org ● http://ilian.i-n-i.org ● https://github.com/IlianIliev/