Building Pluggable Web Applications using Django
Upcoming SlideShare
Loading in...5
×
 

Building Pluggable Web Applications using Django

on

  • 14,163 views

A talk introducing django and using it effectively, at Great Indian Developer Summit.

A talk introducing django and using it effectively, at Great Indian Developer Summit.

Statistics

Views

Total Views
14,163
Views on SlideShare
11,758
Embed Views
2,405

Actions

Likes
22
Downloads
375
Comments
0

17 Embeds 2,405

http://lakshmanprasad.com 1097
http://uswaretech.com 971
http://clasense4.wordpress.com 149
http://www.slideshare.net 49
http://agiliq.com 49
http://becomingguru.github.io 43
http://feeds.feedburner.com 29
http://www.linkedin.com 6
http://translate.googleusercontent.com 2
http://becomingguru.github.com 2
http://xss.yandex.net 2
http://a0.twimg.com 1
http://health.medicbd.com 1
http://buyitnw.appspot.com 1
http://xianguo.com 1
http://webcache.googleusercontent.com 1
http://dimensiweb.wordpress.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

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

Building Pluggable Web Applications using Django Building Pluggable Web Applications using Django Presentation Transcript

  • Introduction Using django Features of django Reuseable apps End Notes Building Pluggable Web Applications using Lakshman Prasad Agiliq Solutions April 21, 2010
  • Introduction Using django Features of django Reuseable apps End Notes • For building database driven web applications
  • Introduction Using django Features of django Reuseable apps End Notes • For building database driven web applications • Emphasis on Reuse, DRY and simplicity
  • Introduction Using django Features of django Reuseable apps End Notes Hypothetical Application
  • Introduction Using django Features of django Reuseable apps End Notes Install a pluggable app django-star-rating $pip install django-star-rating INSTALLED APPS = ( ’ django . c o n t r i b . auth ’ , ’ django . c o n t r i b . contenttypes ’ , ’ django . c o n t r i b . sessions ’ , ’ django . c o n t r i b . sites ’ , ’ django . c o n t r i b . admin ’ , ’ starrating ’ , )
  • Introduction Using django Features of django Reuseable apps End Notes Point to an url pattern urlpatterns = patterns ( ’ ’ , ( r ’ ˆ$ ’ , ’ b l o g . v i e w s . i n d e x ’ ) , ( r ’ s t a r i n g /$ ’ , ’ s t a r r a t i n g . v i e w s . s t a r ’ ) , )
  • Introduction Using django Features of django Reuseable apps End Notes Put the rating where you want! <html> <head> < t i t l e>{{ page . t i t l e }}</ t i t l e> <body> {% s t a r r a t i n g %} <d i v> {{ page . c o n t e n t }} </ d i v> ... </body> ...
  • Introduction Using django Features of django Reuseable apps End Notes Thats it!
  • Introduction Using django Features of django Reuseable apps End Notes Introduction Definition A Case Study: Youtube Stars Overview Philosophy Using django MTV Features of django Features Reuseable apps Writing reuseable apps Community Applications End Notes Django Stats Common Enterprise Hurdles Other
  • Introduction Using django Features of django Reuseable apps End Notes Developed at Lawrence-Journal World
  • 5 million hits per month
  • 600 Contributors
  • Majority of the features community contributed
  • 5 years since Open Source
  • Introduction Using django Features of django Reuseable apps End Notes Philosophy
  • Automate repetitive tasks
  • Make Development Fast
  • Introduction Using django Features of django Reuseable apps End Notes Convention Over Configuration
  • Follow Best Practices
  • Models-Templates-Views
  • Models
  • Introduction Using django Features of django Reuseable apps End Notes Model Syntax from d j a n g o . db import m o d e l s c l a s s P o s t ( m o d e l s . Model ) : t i t l e = m o d e l s . C h a r F i e l d ( m a x l e n g t h =100) t e x t = models . T e x t F i e l d ( ) datetime = models . DateTimeField ( ) c l a s s Meta : o r d e r i n g = ( ’−d a t e t i m e ’ , ) def unicode ( self ): return s e l f . t i t l e c l a s s Comment ( m o d e l s . Model ) : post = models . ForeignKey ( Post ) t e x t = models . T e x t F i e l d ( )
  • Introduction Using django Features of django Reuseable apps End Notes Model API >>>from b l o g . m o d e l s import Post , Comment >>>p o s t = P o s t . o b j e c t s . a l l ( ) [ 0 ] >>>p o s t c o m m e n t s = p o s t . c om m en t s et . a l l ( )
  • Introduction Using django Features of django Reuseable apps End Notes Admin by models alone
  • Introduction Using django Features of django Reuseable apps End Notes Admin Syntax from d j a n g o . c o n t r i b import admin from m o d e l s import Post , Comment c l a s s PostAdmin ( admin . ModelAdmin ) : l i s t d i s p l a y = ( ’ t i t l e ’ , ’ datetime ’ ) c l a s s CommentAdmin ( admin . ModelAdmin ) : l i s t d i s p l a y = ( ’ text ’ ,) admin . s i t e . r e g i s t e r ( Post , PostAdmin ) admin . s i t e . r e g i s t e r ( Comment , CommentAdmin )
  • List Page
  • Add an Entry
  • Auto Validation
  • Introduction Using django Features of django Reuseable apps End Notes Ugly urls h t t p : / / a r t . com/ a r t g a l l e r y / d e f a u l t . a s p ? s i d =9DF4BC0580DF11D3ACB60090271E26A8 &command= f r e e l i s t h t t p : / / p r e v i e w . y n o t . com/ c g i b i n / n d C G I 5 0 . c g i / Y n o t P h o e n i x / CFsMain .
  • Introduction Using django Features of django Reuseable apps End Notes Good urls h t t p : / /www. w i r e d . com/ a p p l e / MacbookPro / h t t p : / / devmarch . com/ d e v e l o p e r s u m m i t / s p e a k e r s . html
  • Introduction Using django Features of django Reuseable apps End Notes django url pattern urlpatterns = patterns ( ’ ’ , ( r ’ ˆ$ ’ , ’ b l o g . v i e w s . i n d e x ’ ) , ( r ’ s t a r i n g /$ ’ , ’ s t a r r a t i n g . v i e w s . s t a r ’ ) , )
  • Views
  • Introduction Using django Features of django Reuseable apps End Notes django views from d j a n g o . h t t p import H t t p R e s p o n s e def p o s t ( r e q u e s t ) : r e t u r n H t t p R e s p o n s e ( ’ H e l l o World ! ’ )
  • Introduction Using django Features of django Reuseable apps End Notes django views def p o s t ( r e q u e s t , p o s t i d ) : p o s t = P o s t . o b j e c t s . g e t ( pk=p o s t i d ) i f r e q . method == ’POST ’ : comment form = CommentForm ( r e q u e s t . POST) comment = comment form . s a v e ( ) payload = { ’ post ’ : post , ’ comments ’ : Comment . o b j e c t s . f i l t e r ( p o s t i d=p o s t i d ) , ’ comment form ’ : CommentForm ( ) } r e t u r n r e n d e r t o r e s p o n s e ( ’ p o s t . html ’ , payload , RequestContext ( req ))
  • Templates
  • Introduction Using django Features of django Reuseable apps End Notes django template {% e x t e n d s ” b a s e . html ” %} {% b l o c k body %} {% i f u s e r . i s a u t h e n t i c a t e d %} Welcome {{ u s e r . g e t f u l l n a m e }} {% e l s e %} {% i n c l u d e ” l o g i n . html ” %} {% e n d i f %} ... {% e n d b l o c k %}
  • Features
  • Introduction Using django Features of django Reuseable apps End Notes • Admin Interface
  • Introduction Using django Features of django Reuseable apps End Notes • Admin Interface • Generic Views
  • Introduction Using django Features of django Reuseable apps End Notes • Admin Interface • Generic Views • Testing Tools
  • Introduction Using django Features of django Reuseable apps End Notes • Admin Interface • Generic Views • Testing Tools • Sessions
  • Introduction Using django Features of django Reuseable apps End Notes • Admin Interface • Generic Views • Testing Tools • Sessions • Authentication
  • Introduction Using django Features of django Reuseable apps End Notes • Admin Interface • Generic Views • Testing Tools • Sessions • Authentication • Caching
  • Introduction Using django Features of django Reuseable apps End Notes • Admin Interface • Generic Views • Testing Tools • Sessions • Authentication • Caching • Internationalization
  • Introduction Using django Features of django Reuseable apps End Notes • Admin Interface • Generic Views • Testing Tools • Sessions • Authentication • Caching • Internationalization • RSS
  • Introduction Using django Features of django Reuseable apps End Notes • Admin Interface • Generic Views • Testing Tools • Sessions • Authentication • Caching • Internationalization • RSS • CSRF protection
  • Introduction Using django Features of django Reuseable apps End Notes • Admin Interface • Generic Views • Testing Tools • Sessions • Authentication • Caching • Internationalization • RSS • CSRF protection • File Storage
  • Django Documentation
  • Introduction Using django Features of django Reuseable apps End Notes General conventions adopted by the community
  • Introduction Using django Features of django Reuseable apps End Notes Use template tags <p>The t i m e i s {% c u r r e n t t i m e ”%I :%M %p” %}.</p> from d j a n g o import t e m p l a t e def d o c u r r e n t t i m e ( p a r s e r , t o k e n ) : tag name , f o r m a t s t r i n g = t o k e n . s p l i t c o n t e n t s ( ) r e t u r n CurrentTimeNode ( f o r m a t s t r i n g [ 1 : − 1 ] )
  • Introduction Using django Features of django Reuseable apps End Notes Use Signals from d j a n g o . c o r e . s i g n a l s import r e q u e s t f i n i s h e d r e q u e s t f i n i s h e d . connect ( my callback ) from d j a n g o . db . m o d e l s . s i g n a l s import p r e s a v e from myapp . m o d e l s import MyModel def m y h a n d l e r ( s e n d e r , ∗∗ k w a r g s ) : ... p r e s a v e . c o n n e c t ( m y h a n d l e r , s e n d e r=MyModel )
  • Introduction Using django Features of django Reuseable apps End Notes Basics • Take template_name and extra_context every where
  • Introduction Using django Features of django Reuseable apps End Notes Basics • Take template_name and extra_context every where • Write urls in applications
  • Introduction Using django Features of django Reuseable apps End Notes Basics • Take template_name and extra_context every where • Write urls in applications • Import from the application level
  • Introduction Using django Features of django Reuseable apps End Notes Basics • Take template_name and extra_context every where • Write urls in applications • Import from the application level • Prefix template name with directory
  • Introduction Using django Features of django Reuseable apps End Notes Basics • Take template_name and extra_context every where • Write urls in applications • Import from the application level • Prefix template name with directory • Use MEDIA_URL in templates
  • Introduction Using django Features of django Reuseable apps End Notes Basics • Take template_name and extra_context every where • Write urls in applications • Import from the application level • Prefix template name with directory • Use MEDIA_URL in templates • Reverse url patterns
  • Introduction Using django Features of django Reuseable apps End Notes Basics Done right def r e g i s t e r ( r e q u e s t , backend , s u c c e s s u r l=None , f o r m c l a s s=None , d i s a l l o w e d u r l= ’ registration disallowed ’ , t e m p l a t e n a m e= ’ r e g i s t r a t i o n / r e g i s t r a t i o n f o r m . html ’ , e x t r a c o n t e x t=None ) : ... return r e n d e r t o r e s p o n s e ( template name , { ’ form ’ : form } , context )
  • Introduction Using django Features of django Reuseable apps End Notes Advanced • Use Template Response
  • Introduction Using django Features of django Reuseable apps End Notes Advanced • Use Template Response • Write Views as Classes
  • There is an app for that
  • For every size and style
  • Introduction Using django Features of django Reuseable apps End Notes Github Search ”django”
  • Introduction Using django Features of django Reuseable apps End Notes
  • Introduction Using django Features of django Reuseable apps End Notes Pinax Features • openid support • email verification • password management • site announcements • a notification framework • user-to-user messaging • friend invitation (both internal and external to the site) • a basic twitter clone • oembed support • gravatar support • interest groups (called tribes) • projects with basic task and issue management • threaded discussions • wikis with multiple markup support • blogging • bookmarks
  • Introduction Using django Features of django Reuseable apps End Notes django-mingus django extensions view cache utils basic contact form flatblocks honeypot disqus sugar navbar quoteme djangodblog django− s t a t i c f i l e s sorl django−b i t l y oembded d j a n g o −t w i t t e r template utils python−t w i t t e r django proxy d j a n g o −wysiwyg compressor d j a n g o −s l i m m e r django markup d j a n g o −c r o p p e r google analytics d j a n g o −r e q u e s t
  • Django users
  • Introduction Using django Features of django Reuseable apps End Notes Popular Users • Media • LA Times • NY Times • Washington Post • Guardian
  • Introduction Using django Features of django Reuseable apps End Notes Popular Users • Media • LA Times • NY Times • Washington Post • Guardian • Web2.0 • Mahalo: 10 million Page views • Pownce, SixApart
  • Introduction Using django Features of django Reuseable apps End Notes Popular Users • Media • LA Times • NY Times • Washington Post • Guardian • Web2.0 • Mahalo: 10 million Page views • Pownce, SixApart • Full List: djangosites.com
  • Introduction Using django Features of django Reuseable apps End Notes NASA After an extensive trade study, we selected Django ... as the first and primary application environment for the Nebula Cloud.
  • Introduction Using django Features of django Reuseable apps End Notes Enterprise Adoption Hurdles • Multiple Databases
  • Introduction Using django Features of django Reuseable apps End Notes Enterprise Adoption Hurdles • Multiple Databases • Dynamic settings infrastructure
  • Introduction Using django Features of django Reuseable apps End Notes Enterprise Adoption Hurdles • Multiple Databases • Dynamic settings infrastructure • Tools
  • Introduction Using django Features of django Reuseable apps End Notes About Me • lakshman@agiliqsolutions.com, @becomingGuru • Agiliq Solutions Formerly, Usware Technologies @agiliq • Team of Expert Django Developers, Happy Clients
  • http://www.agiliqsolutions.com/
  • Introduction Using django Features of django Reuseable apps End Notes Image Attributions h t t p : / /www . f l i c k r . com/ p h o t o s / t e j e d o r o d e l u z /3157690060/ h t t p : / /www . f l i c k r . com/ p h o t o s /23820645 @N05 /4287681570/ h t t p : / /www . f l i c k r . com/ p h o t o s / a i d a n j o n e s /3575000735/ http :// j a c o b i a n . org / h t t p : / / s a n j u a n c o l l e g e . edu / l i b / i m a g e s / p h i l o s o p h y b r a i n . j p g h t t p : / /www . f l i c k r . com/ p h o t o s / uhop /105062059/ h t t p : / / s 3 . amazonaws . com/memebox/ u p l o a d s /136/ e x p o n e n t i a l g r a p h 2 . j p g h t t p : / / g e e k a n d p o k e . t y p e p a d . com/ g e e k a n d p o k e / i m a g e s /2008/06/03/ s e x p l 1 8 . j p g h t t p : / /www . f l i c k r . com/ p h o t o s / go /253819/ h t t p : / / a r o u n d t h e s p h e r e . f i l e s . w o r d p r e s s . com /2009/05/ s w i s s −army−k n i f e . j p g h t t p : / /www . f r e e f o t o . com/ i m a g e s /41/04/41 0 4 9− −Keep−L e f t w e b . j p g − h t t p : / /www . f l i c k r . com/ p h o t o s / o r i n r o b e r t j o h n /114430223/
  • ?