SlideShare a Scribd company logo
1 of 14
Download to read offline
Method-based views
in Django applications
      Gary Reynolds
     Touch Technology

           @goodtune
     bitbucket.org/goodtune
      github.com/goodtune
Refresher

• Last time we looked at building up a library
  which will help save us some boilerplate
• It incorporated better form fields, simple
  decorated mixins to enforce
  authentication, and a few other niceties
This time
 • What if we need to deploy the same
    application multiple times?
 • In our URLconf we could point to the
    applications urls.py as many times as we
    need...
from django.conf.urls.defaults import patterns, url

urlpatterns = patterns('',
    url(r'^usual-use/', 'myapp.urls'),
    url(r'^it/makes/sense/here/too/', 'myapp.urls'),
)
Issues
• If your application requires configuration at
  run-time, you probably use a custom
  settings.MYAPP_VAR or similar?
• That will usually apply globally, not per
  mount point.
• If the application was an instance with it’s
  own state, the issue goes away.
Basic anatomy
class MyApp(object):

   def __init__(self, name='myapp', app_name='myapp'):
       self.name = name
       self.app_name = app_name

   def get_urls(self):
       urlpatterns = patterns('',
           url(r'^$', self.index, name='index'),
       )

   @property
   def urls(self):
       return self.get_urls(), self.app_name, self.name

   def index(self, request):
       return HttpResponse('')
Let’s see it in practice
Horses for courses
• This book store is missing a view for the
  details of a book.
• It really is an admin application, allowing
  authenticated creation and updating of
  Book instances by authenticated users.
• Lets use inheritance to split the
  functionality.
Subclass our application
Real world example
• Tournament Control is an application for
  managing sporting competitions
 • Scheduling fixtures
 • Allocating matches to grounds &
    timeslots
 • Recording results and automatic ladder
    updates
Tournament Control
• Shameless plug
 • http://www.sydney.touch.asn.au/
 • http://www.touchsuperleague.org.uk/
 • http://www.touchworldcup2011.co.uk/
• We’re interested in Touch Superleague
  because they run multiple application
  instances - they have venues in Edinburgh,
  Cardiff, and Jersey.
Lets look at
             the front-end

www.touchsuperleague.org.uk/edinburgh/draws-ladders
Questions?
• Sample project can be obtained from
  bitbucket.org

 • bitbucket.org/goodtune/sydjango-
    example-two

• This presentation can be downloaded from
  SlideShare

 • slideshare.net/goodtune/method-based-
    views-in-django-applications-14050952

More Related Content

What's hot

The Most Valuable Corporate Gifts That Your Employees Will Love
The Most Valuable Corporate Gifts That Your Employees Will LoveThe Most Valuable Corporate Gifts That Your Employees Will Love
The Most Valuable Corporate Gifts That Your Employees Will Love
Augrav
 

What's hot (15)

Active Admin
Active AdminActive Admin
Active Admin
 
Troubleshooting APEX Performance Issues
Troubleshooting APEX Performance IssuesTroubleshooting APEX Performance Issues
Troubleshooting APEX Performance Issues
 
Bare acl
Bare aclBare acl
Bare acl
 
Apache Stratos: the PaaS from Apache
Apache Stratos: the PaaS from ApacheApache Stratos: the PaaS from Apache
Apache Stratos: the PaaS from Apache
 
REST API for your WP7 App
REST API for your WP7 AppREST API for your WP7 App
REST API for your WP7 App
 
The Most Valuable Corporate Gifts That Your Employees Will Love
The Most Valuable Corporate Gifts That Your Employees Will LoveThe Most Valuable Corporate Gifts That Your Employees Will Love
The Most Valuable Corporate Gifts That Your Employees Will Love
 
Get rss to blogger
Get rss to bloggerGet rss to blogger
Get rss to blogger
 
Managing the Pace of Innovation: Behind the Scenes at AWS (SPOT201) | AWS re:...
Managing the Pace of Innovation: Behind the Scenes at AWS (SPOT201) | AWS re:...Managing the Pace of Innovation: Behind the Scenes at AWS (SPOT201) | AWS re:...
Managing the Pace of Innovation: Behind the Scenes at AWS (SPOT201) | AWS re:...
 
Managing the Pace of Innovation: Behind the Scenes at AWS
Managing the Pace of Innovation: Behind the Scenes at AWSManaging the Pace of Innovation: Behind the Scenes at AWS
Managing the Pace of Innovation: Behind the Scenes at AWS
 
EmberJS BucharestJS
EmberJS BucharestJSEmberJS BucharestJS
EmberJS BucharestJS
 
Lighting talk android espesso recorder
Lighting talk   android espesso recorderLighting talk   android espesso recorder
Lighting talk android espesso recorder
 
Apas
ApasApas
Apas
 
Action Bar Sherlock tutorial
Action Bar Sherlock tutorialAction Bar Sherlock tutorial
Action Bar Sherlock tutorial
 
Rails engine
Rails engineRails engine
Rails engine
 
Introduction to ember js
Introduction to ember jsIntroduction to ember js
Introduction to ember js
 

Similar to Method based views in django applications

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
Yared Ayalew
 
Pluggable patterns
Pluggable patternsPluggable patterns
Pluggable patterns
Corey Oordt
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTT
kevinvw
 

Similar to Method based views in django applications (20)

Angular Intermediate
Angular IntermediateAngular Intermediate
Angular Intermediate
 
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
 
Ei cakephp
Ei cakephpEi cakephp
Ei cakephp
 
Cakeph pppt
Cakeph ppptCakeph pppt
Cakeph pppt
 
Pluggable patterns
Pluggable patternsPluggable patterns
Pluggable patterns
 
BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsBackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applications
 
Modern Automated Site Provisioning for SharePoint Online
Modern Automated Site Provisioning for SharePoint OnlineModern Automated Site Provisioning for SharePoint Online
Modern Automated Site Provisioning for SharePoint Online
 
Grails patterns and practices
Grails patterns and practicesGrails patterns and practices
Grails patterns and practices
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
Reusable Apps
Reusable AppsReusable Apps
Reusable Apps
 
Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012
 
Django Overview
Django OverviewDjango Overview
Django Overview
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTT
 
Google app-engine-with-python
Google app-engine-with-pythonGoogle app-engine-with-python
Google app-engine-with-python
 
Google App Engine for Java
Google App Engine for JavaGoogle App Engine for Java
Google App Engine for Java
 
Tango with django
Tango with djangoTango with django
Tango with django
 
(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...
(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...
(BDT402) Performance Profiling in Production: Analyzing Web Requests at Scale...
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
 
Django apps and ORM Beyond the basics [Meetup hosted by Prodeers.com]
Django apps and ORM Beyond the basics [Meetup hosted by Prodeers.com]Django apps and ORM Beyond the basics [Meetup hosted by Prodeers.com]
Django apps and ORM Beyond the basics [Meetup hosted by Prodeers.com]
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
[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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Method based views in django applications

  • 1. Method-based views in Django applications Gary Reynolds Touch Technology @goodtune bitbucket.org/goodtune github.com/goodtune
  • 2. Refresher • Last time we looked at building up a library which will help save us some boilerplate • It incorporated better form fields, simple decorated mixins to enforce authentication, and a few other niceties
  • 3. This time • What if we need to deploy the same application multiple times? • In our URLconf we could point to the applications urls.py as many times as we need... from django.conf.urls.defaults import patterns, url urlpatterns = patterns('', url(r'^usual-use/', 'myapp.urls'), url(r'^it/makes/sense/here/too/', 'myapp.urls'), )
  • 4. Issues • If your application requires configuration at run-time, you probably use a custom settings.MYAPP_VAR or similar? • That will usually apply globally, not per mount point. • If the application was an instance with it’s own state, the issue goes away.
  • 5. Basic anatomy class MyApp(object): def __init__(self, name='myapp', app_name='myapp'): self.name = name self.app_name = app_name def get_urls(self): urlpatterns = patterns('', url(r'^$', self.index, name='index'), ) @property def urls(self): return self.get_urls(), self.app_name, self.name def index(self, request): return HttpResponse('')
  • 6. Let’s see it in practice
  • 7. Horses for courses • This book store is missing a view for the details of a book. • It really is an admin application, allowing authenticated creation and updating of Book instances by authenticated users. • Lets use inheritance to split the functionality.
  • 9. Real world example • Tournament Control is an application for managing sporting competitions • Scheduling fixtures • Allocating matches to grounds & timeslots • Recording results and automatic ladder updates
  • 10. Tournament Control • Shameless plug • http://www.sydney.touch.asn.au/ • http://www.touchsuperleague.org.uk/ • http://www.touchworldcup2011.co.uk/ • We’re interested in Touch Superleague because they run multiple application instances - they have venues in Edinburgh, Cardiff, and Jersey.
  • 11.
  • 12. Lets look at the front-end www.touchsuperleague.org.uk/edinburgh/draws-ladders
  • 14. • Sample project can be obtained from bitbucket.org • bitbucket.org/goodtune/sydjango- example-two • This presentation can be downloaded from SlideShare • slideshare.net/goodtune/method-based- views-in-django-applications-14050952