Introduction To
What is Django ?
●   Django is a high-level Python Web framework
    that encourages rapid development and clean,
    prag...
Django Requirements
●   Python (2.3+)
●   PostgreSQL / MySQL / SQLite / ...
●   Apache + mod_python /mod_wsgi / FastCGI / ...
Features
●   Object- Relation        ●   Unicode support
    Mapper                  ●   Cache framework
●   Templating La...
More Features
●   Jython support           ●   Send emails easily
●   Nice support for forms   ●   Built -in site maps
●  ...
Components
●   Models – Django ORM
●   Templates - Django Templates Engine
●   Views – Python function , Request in , Requ...
Lets Build a Project
$django-admin.py startproject myproject

myproject/
    __init__.py
    manage.py
    settings.py
   ...
Run Server

$ ./manage.py runserver
Validating models...
0 errors found.

Django   version    1.2-pre,   using    settings...
Typical Application Workflow
●   Create application
●   Create models.py and admin.py
●   'python manage.py syncdb'
●   Cr...
Creating models

$python manage.py startapp polls
polls/ __init__.py
      models.py
      tests.py
      views.py
Edit polls/model.py
from django.db import models

        class Poll(models.Model):
              question = models.CharFi...
Continue ...
●   $python manage.py sql polls
    BEGIN;

    CREATE TABLE "polls_poll" (

        "id" serial NOT NULL PRI...
Playing With API
>>> from mysite.polls.models import Poll, Choice # Import the model classes we
just wrote.
# No polls are...
Activate the admin site
Edit the file /mysite/urls.py
from django.conf.urls.defaults import *
# Uncomment the next two lin...
Start the development server
$python manage.py runserver
Now, open a Web browser and go to "/admin/" on your local domain ...
Docs , Books ,People
●   docs.djangoproject.com
●   djangobook.com
●   djangosnippets.com
●   djangopeople.net
●   djangos...
THANKS 


Submited by :-
Jagdeep Singh Malhi
Website :-www.jagdeepmalhi.blogspot.com
Introduction to Django
Upcoming SlideShare
Loading in...5
×

Introduction to Django

2,999

Published on

Published in: Technology, Design
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,999
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
101
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Introduction to Django

  1. 1. Introduction To
  2. 2. What is Django ? ● Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. ● Django makes it easier to build better Web apps more quickly and with less code. ● The Web framework with perfectionists with deadlines.
  3. 3. Django Requirements ● Python (2.3+) ● PostgreSQL / MySQL / SQLite / ... ● Apache + mod_python /mod_wsgi / FastCGI / ...
  4. 4. Features ● Object- Relation ● Unicode support Mapper ● Cache framework ● Templating Language ● Testing framework ● Automatic Language ● Great docs (650+pages ● Elegant ursl ● Friendly community ● MVC architecture
  5. 5. More Features ● Jython support ● Send emails easily ● Nice support for forms ● Built -in site maps ● Built in dcv server ● Built-in RSS/ATOM ● Solid security ● ”Signal” hooks emphasis
  6. 6. Components ● Models – Django ORM ● Templates - Django Templates Engine ● Views – Python function , Request in , Request out ● URL Patterns – Regular expression based
  7. 7. Lets Build a Project $django-admin.py startproject myproject myproject/ __init__.py manage.py settings.py urls.py
  8. 8. Run Server $ ./manage.py runserver Validating models... 0 errors found. Django version 1.2-pre, using settings 'myproject.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
  9. 9. Typical Application Workflow ● Create application ● Create models.py and admin.py ● 'python manage.py syncdb' ● Create urls.py and views.py
  10. 10. Creating models $python manage.py startapp polls polls/ __init__.py models.py tests.py views.py
  11. 11. Edit polls/model.py from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField()
  12. 12. Continue ... ● $python manage.py sql polls BEGIN; CREATE TABLE "polls_poll" ( "id" serial NOT NULL PRIMARY KEY, "question" varchar(200) NOT NULL, "pub_date" timestamp with time zone NOT NULL ); CREATE TABLE "polls_choice" ( "id" serial NOT NULL PRIMARY KEY, "poll_id" integer NOT NULL REFERENCES "polls_poll" ("id"), "choice" varchar(200) NOT NULL, "votes" integer NOT NULL); COMMIT; ● $python manage.py syncdb // update database
  13. 13. Playing With API >>> from mysite.polls.models import Poll, Choice # Import the model classes we just wrote. # No polls are in the system yet. >>> Poll.objects.all() [ ] # Create a new Poll. >>> import datetime >>> p = Poll(question="What's up?", pub_date=datetime.datetime.now()) # Save the object into the database. You have to call save() explicitly. >>> p.save() # Access database columns via Python attributes. >>> p.question "What's up?" >>> p.pub_date datetime.datetime(2007, 7, 15, 12, 00, 53) # Change values by changing the attributes, then calling save(). >>> p.pub_date = datetime.datetime(2007, 4, 1, 0, 0) >>> p.save() # objects.all() displays all the polls in the database. >>> Poll.objects.all() [<Poll: Poll object>]
  14. 14. Activate the admin site Edit the file /mysite/urls.py from django.conf.urls.defaults import * # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # Example: # (r'^mysite/', include('mysite.foo.urls')), # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: (r'^admin/', include(admin.site.urls)), )
  15. 15. Start the development server $python manage.py runserver Now, open a Web browser and go to "/admin/" on your local domain -- e.g., http://127.0.0.1:8000/admin/. You should see the admin's login screen:
  16. 16. Docs , Books ,People ● docs.djangoproject.com ● djangobook.com ● djangosnippets.com ● djangopeople.net ● djangosites.org
  17. 17. THANKS  Submited by :- Jagdeep Singh Malhi Website :-www.jagdeepmalhi.blogspot.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×