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

What is Agile Methodology | Edureka
What is Agile Methodology | EdurekaWhat is Agile Methodology | Edureka
What is Agile Methodology | EdurekaEdureka!
 
Devops Adoption Roadmap v.2.6
Devops Adoption Roadmap v.2.6Devops Adoption Roadmap v.2.6
Devops Adoption Roadmap v.2.6Javier Dominguez
 
IBM Jazz Agile Collaborative Lifecycle Management 6.0.x What's new
IBM Jazz Agile Collaborative Lifecycle Management 6.0.x What's newIBM Jazz Agile Collaborative Lifecycle Management 6.0.x What's new
IBM Jazz Agile Collaborative Lifecycle Management 6.0.x What's newSandra Sergi
 
Agile software development
Agile software developmentAgile software development
Agile software developmentRajesh Piryani
 
Agile presentation
Agile presentationAgile presentation
Agile presentationinfolock
 
Non functional requirements - checklist
Non functional requirements - checklistNon functional requirements - checklist
Non functional requirements - checklistVu Hung Nguyen
 
Scrum guide presentation (Scrum Guide in easy to read PPT format)
Scrum guide presentation (Scrum Guide in easy to read PPT format)Scrum guide presentation (Scrum Guide in easy to read PPT format)
Scrum guide presentation (Scrum Guide in easy to read PPT format)Aloke Bhattacharya
 
DevOps: What, who, why and how?
DevOps: What, who, why and how?DevOps: What, who, why and how?
DevOps: What, who, why and how?Red Gate Software
 
Drive business outcomes using Azure Devops
Drive business outcomes using Azure DevopsDrive business outcomes using Azure Devops
Drive business outcomes using Azure DevopsBelatrix Software
 
Semi-Supervised Learning In An Adversarial Environment
Semi-Supervised Learning In An Adversarial EnvironmentSemi-Supervised Learning In An Adversarial Environment
Semi-Supervised Learning In An Adversarial EnvironmentDataWorks Summit
 
Implementing an Application Security Pipeline in Jenkins
Implementing an Application Security Pipeline in JenkinsImplementing an Application Security Pipeline in Jenkins
Implementing an Application Security Pipeline in JenkinsSuman Sourav
 
Agile Development unleashed
Agile Development unleashedAgile Development unleashed
Agile Development unleashedlivgeni
 

What's hot (20)

What is Agile Methodology | Edureka
What is Agile Methodology | EdurekaWhat is Agile Methodology | Edureka
What is Agile Methodology | Edureka
 
Scrum em 15 minutos
Scrum em 15 minutosScrum em 15 minutos
Scrum em 15 minutos
 
Agile Scrum Methodology
Agile Scrum MethodologyAgile Scrum Methodology
Agile Scrum Methodology
 
Devops Adoption Roadmap v.2.6
Devops Adoption Roadmap v.2.6Devops Adoption Roadmap v.2.6
Devops Adoption Roadmap v.2.6
 
IBM Jazz Agile Collaborative Lifecycle Management 6.0.x What's new
IBM Jazz Agile Collaborative Lifecycle Management 6.0.x What's newIBM Jazz Agile Collaborative Lifecycle Management 6.0.x What's new
IBM Jazz Agile Collaborative Lifecycle Management 6.0.x What's new
 
BookStore
BookStoreBookStore
BookStore
 
Agile software development
Agile software developmentAgile software development
Agile software development
 
Agile presentation
Agile presentationAgile presentation
Agile presentation
 
Software documentation
Software documentationSoftware documentation
Software documentation
 
Non functional requirements - checklist
Non functional requirements - checklistNon functional requirements - checklist
Non functional requirements - checklist
 
Scrum guide presentation (Scrum Guide in easy to read PPT format)
Scrum guide presentation (Scrum Guide in easy to read PPT format)Scrum guide presentation (Scrum Guide in easy to read PPT format)
Scrum guide presentation (Scrum Guide in easy to read PPT format)
 
DevOps: What, who, why and how?
DevOps: What, who, why and how?DevOps: What, who, why and how?
DevOps: What, who, why and how?
 
Sprint backlog
Sprint backlogSprint backlog
Sprint backlog
 
Jira
JiraJira
Jira
 
Drive business outcomes using Azure Devops
Drive business outcomes using Azure DevopsDrive business outcomes using Azure Devops
Drive business outcomes using Azure Devops
 
Semi-Supervised Learning In An Adversarial Environment
Semi-Supervised Learning In An Adversarial EnvironmentSemi-Supervised Learning In An Adversarial Environment
Semi-Supervised Learning In An Adversarial Environment
 
Implementing an Application Security Pipeline in Jenkins
Implementing an Application Security Pipeline in JenkinsImplementing an Application Security Pipeline in Jenkins
Implementing an Application Security Pipeline in Jenkins
 
Introducing scrum
Introducing scrumIntroducing scrum
Introducing scrum
 
Introducing DevOps
Introducing DevOpsIntroducing DevOps
Introducing DevOps
 
Agile Development unleashed
Agile Development unleashedAgile Development unleashed
Agile Development unleashed
 

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

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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
 
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
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
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
 
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 WorkerThousandEyes
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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
 
🐬 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
 
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
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 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
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
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
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 

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