SlideShare a Scribd company logo
1 of 41
An Introduction ,[object Object],[object Object]
Django Reinhardt
ljworld.com
 
www.djangoproject.com
 
 
 
Overview of this Tutorial ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Django's Mission Statement ,[object Object]
Django Requirements ,[object Object],[object Object],[object Object]
“Projects” $ django-admin.py startproject myproject
myproject/ __init__.py manage.py settings.py urls.py
$ ./manage.py runserver Validating models... 0 errors found. Django version 0.96-pre, using settings 'myproject.settings' Development server is running at  http://127.0.0.1:8000/ Quit the server with CONTROL-C.
 
“Apps” $ django-admin.py startapp blog
myproject/ blog/ __init__.py models.py views.py __init__.py manage.py settings.py urls.py
Creating Models from django.db import models class Blog(models.Model): title = models.CharField(maxlength=200) class Post(models.Model): title = models.CharField(maxlength=200) body = models.TextField() blog = models.ForeignKey(Blog) pub_date = models.DateTimeField()
Activating Models $ ./manage.py syncdb Creating table blog_blog Creating table blog_post Loading 'initial_data' fixtures... No fixtures found.
Activating the Admin Interface from django.db import models class Blog(models.Model): title = models.CharField(maxlength=200) class Admin: list_display = ['title'] class Post(models.Model): title = models.CharField(maxlength=200) body = models.TextField() blog = models.ForeignKey(Blog) pub_date = models.DateTimeField() class Admin: list_display = ['title', 'pub_date']
 
 
Model API $ ./manage.py shell >>> from myproject.blog import Blog >>> b = Blog( ...  title=”Jason's Fantastic Blog!!!”) >>> b.save()
>>> all_blogs = Blog.objects.all() >>> print all_blogs [<Blog: Blog object>] >>> print all_blogs.name Jason's Fantastic Blog!!! >>> b = Blog.objects.get(name__contains='Jason') >>> print b.title Jason's Fantastic Blog!!!
URLs ROOT_URLCONF = 'myproject.urls'
URLconfs from django.conf.urls.defaults import * from myproject.blog.views import * urlpatterns = patterns('', (r'^admin/', include('django.contrib.admin.urls')), (r'^blog/$',  post_list), (r'^blog/(?P<id>+)/$', post_list), )
Views from django.http import HttpResponse def post_list(request): return HttpReponse(“This is a list of posts!”)
from django.http import HttpResponse from myproject.blog.models import Post def post_list(request): r = “<ul>” posts = Post.objects.order_by(“-pub_date”) for post in posts: r += “<li>%s: %s</li>” % (post.title, post.body) r += “</ul>” return HttpResponse(r) More realistic...
from django.shorcuts import render_to_response from myproject.blog.models import Post def post_list(request): posts = Post.objects.order_by(“-pub_date”) return render_to_response('blog/post_list.html', { 'post_list': posts, }) Better!
from django.shorcuts import render_to_response from myproject.blog.models import Post def post_detail(request, id): post = get_object_or_404(Post, id=id) return render_to_response('blog/post_detail.html', { 'post': post, }) For completeness...
Templates <html> <body> <h1>Jason's Fantastic Blog!!!</h1> <ul> {% for p in post_list %} <li> <a href=”{{ p.id }}/”>{{ p.title|escape }}</a> </li> {% endfor %} </ul> </body> </html>
The magic dot ,[object Object],[object Object],[object Object]
Filters {{ var|escape|linebreaks|... }}
base.html <html> <head> <title>{% block title %}{% endblock %} </head> <body> <div id=”content”> {% block content %}{% endblock %} </div> <div id=”footer”> {% block footer %} Copyright Jason Davies 2007. {% endblock %} </div> </body> </html>
{% extends “base.html” %} {% block title %} Posts | {{ block.super }} {% endblock %} {% block content %} <h1>Blog Posts ({{ post_list|length }} total)</h1> <ul> {% for post in post_list %} <li> <a href=”{{ post.id }}/”> {{ post.title|escape }} </a> </li> {% endfor %} </ul> {% endblock %}
Ruby on Rails http://www.rubyonrails.org/
http://www.alrond.com/en/2007/jan/25/performance-test-of-6-leading-frameworks/
Thank you for listening. Jason Davies [email_address] http://www.jasondavies.com/
http://www.mercurytide.co.uk/whitepapers/django-cheat-sheet/
 
 

More Related Content

What's hot

Web development with django - Basics Presentation
Web development with django - Basics PresentationWeb development with django - Basics Presentation
Web development with django - Basics PresentationShrinath Shenoy
 
Introduction to django framework
Introduction to django frameworkIntroduction to django framework
Introduction to django frameworkKnoldus Inc.
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django IntroductionGanga Ram
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersRosario Renga
 
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
 
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
 
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!
 
Angular 8
Angular 8 Angular 8
Angular 8 Sunil OS
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2fishwarter
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture IntroductionHaiqi Chen
 

What's hot (20)

Web development with django - Basics Presentation
Web development with django - Basics PresentationWeb development with django - Basics Presentation
Web development with django - Basics Presentation
 
Django
DjangoDjango
Django
 
Introduction to django framework
Introduction to django frameworkIntroduction to django framework
Introduction to django framework
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python Developers
 
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
 
Django
DjangoDjango
Django
 
DJango
DJangoDJango
DJango
 
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
 
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...
 
Angular 8
Angular 8 Angular 8
Angular 8
 
Django
DjangoDjango
Django
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
 
Python/Django Training
Python/Django TrainingPython/Django Training
Python/Django Training
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
Basic Python Django
Basic Python DjangoBasic Python Django
Basic Python Django
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 

Viewers also liked

The Django Web Application Framework
The Django Web Application FrameworkThe Django Web Application Framework
The Django Web Application FrameworkSimon Willison
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using DjangoNathan Eror
 
Getting Started With Django
Getting Started With DjangoGetting Started With Django
Getting Started With Djangojeff_croft
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best PracticesDavid Arcos
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonNowell Strite
 
Starters with Django
Starters with Django Starters with Django
Starters with Django BeDjango
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of DjangoJacob Kaplan-Moss
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Django nutshell overview
Django nutshell overviewDjango nutshell overview
Django nutshell overviewschacki
 
Django & Buildout
Django & BuildoutDjango & Buildout
Django & Buildoutzerok
 
Django shop
Django shopDjango shop
Django shopTribaal
 

Viewers also liked (17)

Django introduction
Django introductionDjango introduction
Django introduction
 
The Django Web Application Framework
The Django Web Application FrameworkThe Django Web Application Framework
The Django Web Application Framework
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
 
Getting Started With Django
Getting Started With DjangoGetting Started With Django
Getting Started With Django
 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real World
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best Practices
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Free django
Free djangoFree django
Free django
 
Starters with Django
Starters with Django Starters with Django
Starters with Django
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
Django Best Practices
Django Best PracticesDjango Best Practices
Django Best Practices
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
dJango
dJangodJango
dJango
 
Django nutshell overview
Django nutshell overviewDjango nutshell overview
Django nutshell overview
 
Django & Buildout
Django & BuildoutDjango & Buildout
Django & Buildout
 
Django shop
Django shopDjango shop
Django shop
 
Why Django
Why DjangoWhy Django
Why Django
 

Similar to Django for Beginners

Mini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesMini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesLeonardo Fernandes
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim Rocha
 
Django for mobile applications
Django for mobile applicationsDjango for mobile applications
Django for mobile applicationsHassan Abid
 
DJ-06-Views-Templates.pptx
DJ-06-Views-Templates.pptxDJ-06-Views-Templates.pptx
DJ-06-Views-Templates.pptxDamien Raczy
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Djangofool2nd
 
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimDjango Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimMir Nazim
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!David 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 - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosIgor Sobreira
 

Similar to Django for Beginners (20)

Django
DjangoDjango
Django
 
Mini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesMini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico Ces
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Django
DjangoDjango
Django
 
Django for mobile applications
Django for mobile applicationsDjango for mobile applications
Django for mobile applications
 
Mini Curso de Django
Mini Curso de DjangoMini Curso de Django
Mini Curso de Django
 
DJ-06-Views-Templates.pptx
DJ-06-Views-Templates.pptxDJ-06-Views-Templates.pptx
DJ-06-Views-Templates.pptx
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimDjango Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030
 
Django web framework
Django web frameworkDjango web framework
Django web framework
 
Django Vs Rails
Django Vs RailsDjango Vs Rails
Django Vs Rails
 
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
 
Django tricks (2)
Django tricks (2)Django tricks (2)
Django tricks (2)
 
React django
React djangoReact django
React django
 
Django
DjangoDjango
Django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Django - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazos
 
Django crush course
Django crush course Django crush course
Django crush course
 

Recently uploaded

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Django for Beginners

  • 1.
  • 4.  
  • 6.  
  • 7.  
  • 8.  
  • 9.
  • 10.
  • 11.
  • 12. “Projects” $ django-admin.py startproject myproject
  • 13. myproject/ __init__.py manage.py settings.py urls.py
  • 14. $ ./manage.py runserver Validating models... 0 errors found. Django version 0.96-pre, using settings 'myproject.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
  • 15.  
  • 17. myproject/ blog/ __init__.py models.py views.py __init__.py manage.py settings.py urls.py
  • 18. Creating Models from django.db import models class Blog(models.Model): title = models.CharField(maxlength=200) class Post(models.Model): title = models.CharField(maxlength=200) body = models.TextField() blog = models.ForeignKey(Blog) pub_date = models.DateTimeField()
  • 19. Activating Models $ ./manage.py syncdb Creating table blog_blog Creating table blog_post Loading 'initial_data' fixtures... No fixtures found.
  • 20. Activating the Admin Interface from django.db import models class Blog(models.Model): title = models.CharField(maxlength=200) class Admin: list_display = ['title'] class Post(models.Model): title = models.CharField(maxlength=200) body = models.TextField() blog = models.ForeignKey(Blog) pub_date = models.DateTimeField() class Admin: list_display = ['title', 'pub_date']
  • 21.  
  • 22.  
  • 23. Model API $ ./manage.py shell >>> from myproject.blog import Blog >>> b = Blog( ... title=”Jason's Fantastic Blog!!!”) >>> b.save()
  • 24. >>> all_blogs = Blog.objects.all() >>> print all_blogs [<Blog: Blog object>] >>> print all_blogs.name Jason's Fantastic Blog!!! >>> b = Blog.objects.get(name__contains='Jason') >>> print b.title Jason's Fantastic Blog!!!
  • 25. URLs ROOT_URLCONF = 'myproject.urls'
  • 26. URLconfs from django.conf.urls.defaults import * from myproject.blog.views import * urlpatterns = patterns('', (r'^admin/', include('django.contrib.admin.urls')), (r'^blog/$', post_list), (r'^blog/(?P<id>+)/$', post_list), )
  • 27. Views from django.http import HttpResponse def post_list(request): return HttpReponse(“This is a list of posts!”)
  • 28. from django.http import HttpResponse from myproject.blog.models import Post def post_list(request): r = “<ul>” posts = Post.objects.order_by(“-pub_date”) for post in posts: r += “<li>%s: %s</li>” % (post.title, post.body) r += “</ul>” return HttpResponse(r) More realistic...
  • 29. from django.shorcuts import render_to_response from myproject.blog.models import Post def post_list(request): posts = Post.objects.order_by(“-pub_date”) return render_to_response('blog/post_list.html', { 'post_list': posts, }) Better!
  • 30. from django.shorcuts import render_to_response from myproject.blog.models import Post def post_detail(request, id): post = get_object_or_404(Post, id=id) return render_to_response('blog/post_detail.html', { 'post': post, }) For completeness...
  • 31. Templates <html> <body> <h1>Jason's Fantastic Blog!!!</h1> <ul> {% for p in post_list %} <li> <a href=”{{ p.id }}/”>{{ p.title|escape }}</a> </li> {% endfor %} </ul> </body> </html>
  • 32.
  • 34. base.html <html> <head> <title>{% block title %}{% endblock %} </head> <body> <div id=”content”> {% block content %}{% endblock %} </div> <div id=”footer”> {% block footer %} Copyright Jason Davies 2007. {% endblock %} </div> </body> </html>
  • 35. {% extends “base.html” %} {% block title %} Posts | {{ block.super }} {% endblock %} {% block content %} <h1>Blog Posts ({{ post_list|length }} total)</h1> <ul> {% for post in post_list %} <li> <a href=”{{ post.id }}/”> {{ post.title|escape }} </a> </li> {% endfor %} </ul> {% endblock %}
  • 36. Ruby on Rails http://www.rubyonrails.org/
  • 38. Thank you for listening. Jason Davies [email_address] http://www.jasondavies.com/
  • 40.  
  • 41.  

Editor's Notes

  1. Hello! My name is Jason Davies; I&apos;m a freelance Web developer from Cambridge and I&apos;ve been using Django for about 2 years ever since it was open-sourced in July 2005. Hopefully this will give you a good introduction to the basics of Django. Simon Willison will cover even more stuff in the advanced tutorial.