Introduction to Django
Upcoming SlideShare
Loading in...5
×
 

Introduction to Django

on

  • 2,801 views

 

Statistics

Views

Total Views
2,801
Views on SlideShare
2,571
Embed Views
230

Actions

Likes
4
Downloads
97
Comments
0

3 Embeds 230

http://achugh.wordpress.com 207
https://achugh.wordpress.com 21
http://cloud.feedly.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Introduction to Django Introduction to Django Presentation Transcript

    • Introduction To
    • 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.
    • Django Requirements ● Python (2.3+) ● PostgreSQL / MySQL / SQLite / ... ● Apache + mod_python /mod_wsgi / FastCGI / ...
    • Features ● Object- Relation ● Unicode support Mapper ● Cache framework ● Templating Language ● Testing framework ● Automatic Language ● Great docs (650+pages ● Elegant ursl ● Friendly community ● MVC architecture
    • 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
    • Components ● Models – Django ORM ● Templates - Django Templates Engine ● Views – Python function , Request in , Request out ● URL Patterns – Regular expression based
    • Lets Build a Project $django-admin.py startproject myproject myproject/ __init__.py manage.py settings.py urls.py
    • 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.
    • Typical Application Workflow ● Create application ● Create models.py and admin.py ● 'python manage.py syncdb' ● Create urls.py and views.py
    • 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.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()
    • 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
    • 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>]
    • 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)), )
    • 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:
    • Docs , Books ,People ● docs.djangoproject.com ● djangobook.com ● djangosnippets.com ● djangopeople.net ● djangosites.org
    • THANKS  Submited by :- Jagdeep Singh Malhi Website :-www.jagdeepmalhi.blogspot.com