• Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,709
On Slideshare
0
From Embeds
0
Number of Embeds
5

Actions

Shares
Downloads
100
Comments
0
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Introduction To
  • 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. Django Requirements ● Python (2.3+) ● PostgreSQL / MySQL / SQLite / ... ● Apache + mod_python /mod_wsgi / FastCGI / ...
  • 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. 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. Components ● Models – Django ORM ● Templates - Django Templates Engine ● Views – Python function , Request in , Request out ● URL Patterns – Regular expression based
  • 7. Lets Build a Project $django-admin.py startproject myproject myproject/ __init__.py manage.py settings.py urls.py
  • 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. Typical Application Workflow ● Create application ● Create models.py and admin.py ● 'python manage.py syncdb' ● Create urls.py and views.py
  • 10. Creating models $python manage.py startapp polls polls/ __init__.py models.py tests.py views.py
  • 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. 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. 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. 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. 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. Docs , Books ,People ● docs.djangoproject.com ● djangobook.com ● djangosnippets.com ● djangopeople.net ● djangosites.org
  • 17. THANKS  Submited by :- Jagdeep Singh Malhi Website :-www.jagdeepmalhi.blogspot.com