SlideShare une entreprise Scribd logo
1  sur  28
Télécharger pour lire hors ligne
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?

Contenu connexe

Tendances

Angular Advanced Routing
Angular Advanced RoutingAngular Advanced Routing
Angular Advanced RoutingLaurent Duveau
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JSArno Lordkronos
 
What is Django | Django Tutorial for Beginners | Python Django Training | Edu...
What is Django | Django Tutorial for Beginners | Python Django Training | Edu...What is Django | Django Tutorial for Beginners | Python Django Training | Edu...
What is Django | Django Tutorial for Beginners | Python Django Training | Edu...Edureka!
 
Estrategias branching: trabajando con git y personas
 Estrategias branching: trabajando con git y personas Estrategias branching: trabajando con git y personas
Estrategias branching: trabajando con git y personasJesús López de la Cruz
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web APIBrad Genereaux
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Knoldus Inc.
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
Fundamentals of Web Development For Non-Developers
Fundamentals of Web Development For Non-DevelopersFundamentals of Web Development For Non-Developers
Fundamentals of Web Development For Non-DevelopersLemi Orhan Ergin
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web APIhabib_786
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
Scraping the web with Laravel, Dusk, Docker, and PHP
Scraping the web with Laravel, Dusk, Docker, and PHPScraping the web with Laravel, Dusk, Docker, and PHP
Scraping the web with Laravel, Dusk, Docker, and PHPPaul Redmond
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_contentNAVEENSAGGAM1
 

Tendances (20)

Angular Advanced Routing
Angular Advanced RoutingAngular Advanced Routing
Angular Advanced Routing
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Angularjs PPT
Angularjs PPTAngularjs PPT
Angularjs PPT
 
What is Django | Django Tutorial for Beginners | Python Django Training | Edu...
What is Django | Django Tutorial for Beginners | Python Django Training | Edu...What is Django | Django Tutorial for Beginners | Python Django Training | Edu...
What is Django | Django Tutorial for Beginners | Python Django Training | Edu...
 
GitHub Presentation
GitHub PresentationGitHub Presentation
GitHub Presentation
 
Estrategias branching: trabajando con git y personas
 Estrategias branching: trabajando con git y personas Estrategias branching: trabajando con git y personas
Estrategias branching: trabajando con git y personas
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
 
Introducing DevOps
Introducing DevOpsIntroducing DevOps
Introducing DevOps
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
AngularJS
AngularJS AngularJS
AngularJS
 
Fundamentals of Web Development For Non-Developers
Fundamentals of Web Development For Non-DevelopersFundamentals of Web Development For Non-Developers
Fundamentals of Web Development For Non-Developers
 
Xapian介绍
Xapian介绍Xapian介绍
Xapian介绍
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
Scraping the web with Laravel, Dusk, Docker, and PHP
Scraping the web with Laravel, Dusk, Docker, and PHPScraping the web with Laravel, Dusk, Docker, and PHP
Scraping the web with Laravel, Dusk, Docker, and PHP
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_content
 

Similaire à Best Practices for Front-End Django Developers

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
 

Similaire à Best Practices for Front-End Django Developers (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...
 

Dernier

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
 
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...Enterprise Knowledge
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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 slidevu2urc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Dernier (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...
 
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...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
[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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Best Practices for Front-End Django Developers

  • 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