SlideShare a Scribd company logo
1 of 28
Download to read offline
BEST PRACTICES FOR
FRONT-END DJANGO
   DEVELOPERS
    Presentation by Christine Cheung
About the Presenter

Front End Developer at RED Interactive Agency

PyLadies board member


http://www.xtine.net

@webdevgirl



     Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
Presentation is Important

Polished front-end is as important as the back-end

  It may “scale” ...

  But bloated markup and JavaScript will slow performance

The implementation of the design is what the user notices.



     Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
TEMPLATING
Start Organized
Structure the hierarchy of static and template files.

  Folders for each app in templates




      Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
Starting Templates

Start with base.html

  Extend from there - index/about/contact.html etc

Blocks for common elements {%                  block title %} {% endblock title %}




Include template files          {% include "foo.html" %}




     Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
Template Tags and Filters
The template system is meant to express presentation, not logic

  Presentation and iteration over data, NOT manipulation

Make your own template tag
                                          from django import template
  Example
                                          register = template.Library()

                                          def dashreplace(value, arg):
                                              return value.replace(arg, '-')

                                          register.filter('dashreplace', dashreplace)



     Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
CSS + JAVASCRIPT
Cascading Style Sheets
                                                   + Header / #header
Define a Style Guide
                                                   + Content / #content
                                                       - Left column / #leftcolumn
Consistent Variable Naming                             - Right column / #rightcolumn
                                                       - Sidebar / #sidebar
                                                           - Search / #search
  Camel Case vs Dashes                             + Footer / #footer

                                                   Advertisements           .ads
Organize into separate files                       Content header           h2

                                                   Dark grey (text): #333333
                                                   Dark Blue (headings, links) #000066




     Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
Using a JavaScript Library

Use only one library (jQuery) and stick to it!

  Avoid plug-in overkill, no more than 3-4

     Reduce performance hits and code conflicts.

     Analyze if you can write your own.




  Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
JavaScript Namespacing

                                                          var someNamespace = (function() {
Namespace your JavaScript
                                                               var animal = “pony”;


  Prevent conflicts                                            var greeting = function () {
                                                                   return “I’m a ” + animal;
                                                               };

  Easier to read and maintain                                  return {

                                                                    foo : function() {
Don’t have to use        $(document).ready()
                                                                    },
                                                                        // do stuff here

                                                                    bar : function() {
                                                                        // do stuff here
                                                                    }

                                                               };

                                                          })();


     Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
JavaScript Don’ts
DO NOT:
 document.write('foo');	
  	
  

 <a	
  onclick="myClickFunction()"	
  href="http://foo.com"></a>	
  	
  

 <a	
  href="javascript:doSomething()"></a>


DO:
 <a	
  class="link"	
  href="http://foo.com"></a>

 $('.link').click(function() { // do stuff });




      Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
Heavy Usage of JavaScript


For front-end heavy websites, check out Backbone.js

  Hook up with RESTful interfaces (TastyPie)

Underscore.js for more utility functions

  object and data manipulation



     Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
TOOLS FOR RAPID
 DEVELOPMENT
Don’t Start HTML from
        Scratch

        HTML5 Boilerplate
           base.html starting point

           CSS Reset (normalize.css)

           jQuery + Modernizr




Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
Modernizr

JavaScript library to detect HTML5 + CSS3 technologies

Detect the features, NOT the browser

HTML5 elements for IE




     Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
Modernizr Examples



.no-cssgradients {                                            Modernizr.load({
    background: url("images/glossybutton.png");
                                                                  test: Modernizr.geolocation,
}
                                                                  yep : 'geo.js',
.cssgradients {                                                   nope: 'geo-polyfill.js'
    background-image: linear-gradient(top, #555, #333);       });
}




            Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
Compass Framework
CSS Authoring Framework + Utilities
  SASS - nested rules, variables, mixins
  Image Spriting
                                                    $blue = #010db5;

     @include border-radius(4px, 4px);              #navbar {
                                                        width: 80%;
      -webkit-border-radius: 4px 4px;
                                                        height: 23px;
      -moz-border-radius: 4px / 4px;
                                                         ul { list-style-type: none; }
      -o-border-radius: 4px / 4px;
                                                         li {
      -ms-border-radius: 4px / 4px;
                                                              float: left;
      -khtml-border-radius: 4px / 4px;
                                                              a { font-weight: bold; }
      border-radius: 4px / 4px; }                             &:last-child { color: $blue; }
                                                         }
                                                    }



     Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
Compass Integration

django-compass

PyScss

  SASS Compiler for Python


Tip: Don’t deploy Compass, put it in project root folder



    Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
DATA HANDLING
All About the Data

Leverage the power of both the front and back end

 Share the work between them

 Class Based Views for quick prototyping

Beware of Caching



   Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
Define Your Data Types

Before any coding happens:

  Write out the API - evaluate the design

  Know when to make a View vs API

  Context Processors



Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
TESTING AND
PERFORMANCE
Let’s Test!
          CSSLint
          JSLint
              warning: will make you cry


          Google Closure Compiler

function hello(name) {
    alert('Hello, ' + name);                          function hello(a){alert("Hello,
}                                                     "+a)}hello("New user");

hello('New user');




       Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
Performance Tips


Build script(s) to minify and gzip files
  TEMPLATE_DEBUG

    settings flag to toggle between flat/compiled static files

Asynchronous / lazy loading JavaScript



     Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
Wrap Up
Consistent folder structures and document style guides

Use a JavaScript library and modern authoring techniques

Leverage data loading between the front and the back ends

Use HTML Boilerplate + CSS/JS tools to your advantage

Think about testing and performance of front-end code



     Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
Resources
CSS Style Guide: http://coding.smashingmagazine.com/2008/05/02/improving-code-
readability-with-css-styleguides/

Front-End Development Guidelines: http://taitems.github.com/Front-End-Development-
Guidelines/

Outdated JavaScript: http://davidbcalhoun.com/2011/how-to-spot-outdated-javascript

Namespaces in JavaScript: http://blog.stannard.net.au/2011/01/14/creating-namespaces-in-
javascript/

HTML5 Boilerplate: http://html5boilerplate.com/

Compass Framework: http://compass-lang.com/

SASS: http://sass-lang.com/



        Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
QUESTIONS?

More Related Content

What's hot

SRS for Hospital Management System
SRS for Hospital Management SystemSRS for Hospital Management System
SRS for Hospital Management Systemkataria Arvind
 
Moodle Mobile offline features
Moodle Mobile offline featuresMoodle Mobile offline features
Moodle Mobile offline featuresJuan Leyva Delgado
 
Clickbank Affiliate Marketing Guide free download
Clickbank Affiliate Marketing Guide free downloadClickbank Affiliate Marketing Guide free download
Clickbank Affiliate Marketing Guide free downloadMichael Gerke
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best PracticesDavid Arcos
 
Library management system
Library management systemLibrary management system
Library management systemsiddiqui241993
 
Microsoft Power BI
Microsoft Power BIMicrosoft Power BI
Microsoft Power BIGeetika
 
Library Management System Project in C
Library Management System Project in CLibrary Management System Project in C
Library Management System Project in Ccodewithc
 
Introduction to Progressive web app (PWA)
Introduction to Progressive web app (PWA)Introduction to Progressive web app (PWA)
Introduction to Progressive web app (PWA)Zhentian Wan
 
Software engineering project(srs)!!
Software engineering project(srs)!!Software engineering project(srs)!!
Software engineering project(srs)!!sourav verma
 
Bank Management System Desktop Application
Bank Management System Desktop Application Bank Management System Desktop Application
Bank Management System Desktop Application Ibadullah Khan
 
Google Apps for Education 101
Google Apps for Education 101Google Apps for Education 101
Google Apps for Education 101classtechie
 
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareSTOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareEmpowered Presentations
 
Library management system
Library management systemLibrary management system
Library management systemArman Ahmed
 
PowerBI: Soluciones, Aplicaciones y Cursos
PowerBI: Soluciones, Aplicaciones y CursosPowerBI: Soluciones, Aplicaciones y Cursos
PowerBI: Soluciones, Aplicaciones y CursosStratebi
 

What's hot (20)

Wikipedia
WikipediaWikipedia
Wikipedia
 
Online news 365
Online news 365Online news 365
Online news 365
 
Billing project
Billing projectBilling project
Billing project
 
SRS for Hospital Management System
SRS for Hospital Management SystemSRS for Hospital Management System
SRS for Hospital Management System
 
Moodle Mobile offline features
Moodle Mobile offline featuresMoodle Mobile offline features
Moodle Mobile offline features
 
Clickbank Affiliate Marketing Guide free download
Clickbank Affiliate Marketing Guide free downloadClickbank Affiliate Marketing Guide free download
Clickbank Affiliate Marketing Guide free download
 
OneDrive Presentation
OneDrive PresentationOneDrive Presentation
OneDrive Presentation
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best Practices
 
Library management system
Library management systemLibrary management system
Library management system
 
Microsoft Power BI
Microsoft Power BIMicrosoft Power BI
Microsoft Power BI
 
Library Management System Project in C
Library Management System Project in CLibrary Management System Project in C
Library Management System Project in C
 
Introduction to Progressive web app (PWA)
Introduction to Progressive web app (PWA)Introduction to Progressive web app (PWA)
Introduction to Progressive web app (PWA)
 
Software engineering project(srs)!!
Software engineering project(srs)!!Software engineering project(srs)!!
Software engineering project(srs)!!
 
Bank Management System Desktop Application
Bank Management System Desktop Application Bank Management System Desktop Application
Bank Management System Desktop Application
 
Student record
Student recordStudent record
Student record
 
Google Apps for Education 101
Google Apps for Education 101Google Apps for Education 101
Google Apps for Education 101
 
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareSTOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
 
Microsoft PowerApps
Microsoft PowerAppsMicrosoft PowerApps
Microsoft PowerApps
 
Library management system
Library management systemLibrary management system
Library management system
 
PowerBI: Soluciones, Aplicaciones y Cursos
PowerBI: Soluciones, Aplicaciones y CursosPowerBI: Soluciones, Aplicaciones y Cursos
PowerBI: Soluciones, Aplicaciones y Cursos
 

Similar to Best Practices for Front-End Django Devs

Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007Guillaume Laforge
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...Codemotion
 
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishGrails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishSven Haiges
 
Web performance essentials - Goodies
Web performance essentials - GoodiesWeb performance essentials - Goodies
Web performance essentials - GoodiesJerry Emmanuel
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Developmentvito jeng
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1Paras Mendiratta
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Guillaume Laforge
 
The Power of Rails 2.3 Engines & Templates
The Power of Rails 2.3 Engines & TemplatesThe Power of Rails 2.3 Engines & Templates
The Power of Rails 2.3 Engines & TemplatesTse-Ching Ho
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracketjnewmanux
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJames Casey
 
Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!cloudbring
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amfrailsconf
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoRodolfo Carvalho
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 

Similar to Best Practices for Front-End Django Devs (20)

"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
 
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishGrails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
Web performance essentials - Goodies
Web performance essentials - GoodiesWeb performance essentials - Goodies
Web performance essentials - Goodies
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
 
The Power of Rails 2.3 Engines & Templates
The Power of Rails 2.3 Engines & TemplatesThe Power of Rails 2.3 Engines & Templates
The Power of Rails 2.3 Engines & Templates
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracket
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
 
Flex With Rubyamf
Flex With RubyamfFlex With Rubyamf
Flex With Rubyamf
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
JavaScripts & jQuery
JavaScripts & jQueryJavaScripts & jQuery
JavaScripts & jQuery
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX Go
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 

Recently uploaded

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 

Recently uploaded (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 

Best Practices for Front-End Django Devs

  • 1. BEST PRACTICES FOR FRONT-END DJANGO DEVELOPERS Presentation by Christine Cheung
  • 2. About the Presenter Front End Developer at RED Interactive Agency PyLadies board member http://www.xtine.net @webdevgirl Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 3. Presentation is Important Polished front-end is as important as the back-end It may “scale” ... But bloated markup and JavaScript will slow performance The implementation of the design is what the user notices. Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 5. Start Organized Structure the hierarchy of static and template files. Folders for each app in templates Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 6. Starting Templates Start with base.html Extend from there - index/about/contact.html etc Blocks for common elements {% block title %} {% endblock title %} Include template files {% include "foo.html" %} Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 7. Template Tags and Filters The template system is meant to express presentation, not logic Presentation and iteration over data, NOT manipulation Make your own template tag from django import template Example register = template.Library() def dashreplace(value, arg): return value.replace(arg, '-') register.filter('dashreplace', dashreplace) Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 9. Cascading Style Sheets + Header / #header Define a Style Guide + Content / #content - Left column / #leftcolumn Consistent Variable Naming - Right column / #rightcolumn - Sidebar / #sidebar - Search / #search Camel Case vs Dashes + Footer / #footer Advertisements .ads Organize into separate files Content header h2 Dark grey (text): #333333 Dark Blue (headings, links) #000066 Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 10. Using a JavaScript Library Use only one library (jQuery) and stick to it! Avoid plug-in overkill, no more than 3-4 Reduce performance hits and code conflicts. Analyze if you can write your own. Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 11. JavaScript Namespacing var someNamespace = (function() { Namespace your JavaScript var animal = “pony”; Prevent conflicts var greeting = function () { return “I’m a ” + animal; }; Easier to read and maintain return { foo : function() { Don’t have to use $(document).ready() }, // do stuff here bar : function() { // do stuff here } }; })(); Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 12. JavaScript Don’ts DO NOT: document.write('foo');     <a  onclick="myClickFunction()"  href="http://foo.com"></a>     <a  href="javascript:doSomething()"></a> DO: <a  class="link"  href="http://foo.com"></a> $('.link').click(function() { // do stuff }); Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 13. Heavy Usage of JavaScript For front-end heavy websites, check out Backbone.js Hook up with RESTful interfaces (TastyPie) Underscore.js for more utility functions object and data manipulation Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 14. TOOLS FOR RAPID DEVELOPMENT
  • 15. Don’t Start HTML from Scratch HTML5 Boilerplate base.html starting point CSS Reset (normalize.css) jQuery + Modernizr Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 16. Modernizr JavaScript library to detect HTML5 + CSS3 technologies Detect the features, NOT the browser HTML5 elements for IE Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 17. Modernizr Examples .no-cssgradients { Modernizr.load({ background: url("images/glossybutton.png"); test: Modernizr.geolocation, } yep : 'geo.js', .cssgradients { nope: 'geo-polyfill.js' background-image: linear-gradient(top, #555, #333); }); } Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 18. Compass Framework CSS Authoring Framework + Utilities SASS - nested rules, variables, mixins Image Spriting $blue = #010db5; @include border-radius(4px, 4px); #navbar { width: 80%; -webkit-border-radius: 4px 4px; height: 23px; -moz-border-radius: 4px / 4px; ul { list-style-type: none; } -o-border-radius: 4px / 4px; li { -ms-border-radius: 4px / 4px; float: left; -khtml-border-radius: 4px / 4px; a { font-weight: bold; } border-radius: 4px / 4px; } &:last-child { color: $blue; } } } Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 19. Compass Integration django-compass PyScss SASS Compiler for Python Tip: Don’t deploy Compass, put it in project root folder Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 21. All About the Data Leverage the power of both the front and back end Share the work between them Class Based Views for quick prototyping Beware of Caching Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 22. Define Your Data Types Before any coding happens: Write out the API - evaluate the design Know when to make a View vs API Context Processors Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 24. Let’s Test! CSSLint JSLint warning: will make you cry Google Closure Compiler function hello(name) { alert('Hello, ' + name); function hello(a){alert("Hello, } "+a)}hello("New user"); hello('New user'); Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 25. Performance Tips Build script(s) to minify and gzip files TEMPLATE_DEBUG settings flag to toggle between flat/compiled static files Asynchronous / lazy loading JavaScript Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 26. Wrap Up Consistent folder structures and document style guides Use a JavaScript library and modern authoring techniques Leverage data loading between the front and the back ends Use HTML Boilerplate + CSS/JS tools to your advantage Think about testing and performance of front-end code Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011
  • 27. Resources CSS Style Guide: http://coding.smashingmagazine.com/2008/05/02/improving-code- readability-with-css-styleguides/ Front-End Development Guidelines: http://taitems.github.com/Front-End-Development- Guidelines/ Outdated JavaScript: http://davidbcalhoun.com/2011/how-to-spot-outdated-javascript Namespaces in JavaScript: http://blog.stannard.net.au/2011/01/14/creating-namespaces-in- javascript/ HTML5 Boilerplate: http://html5boilerplate.com/ Compass Framework: http://compass-lang.com/ SASS: http://sass-lang.com/ Best Practices for Front-End Django Developers by Christine Cheung - DjangoCon 2011