SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
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?

Weitere ähnliche Inhalte

Was ist angesagt?

EMC Documentum - xCP 2.x Troubleshooting
EMC Documentum - xCP 2.x TroubleshootingEMC Documentum - xCP 2.x Troubleshooting
EMC Documentum - xCP 2.x TroubleshootingHaytham Ghandour
 
Introducing SAFe 5.0 the operating system for Business Agility
Introducing SAFe 5.0 the operating system for Business AgilityIntroducing SAFe 5.0 the operating system for Business Agility
Introducing SAFe 5.0 the operating system for Business AgilityLeanwisdom
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesLewis Lin 🦊
 
An introduction to SQLAlchemy
An introduction to SQLAlchemyAn introduction to SQLAlchemy
An introduction to SQLAlchemymengukagan
 
Agile vs Waterfall | Difference between Agile and Waterfall | Edureka
Agile vs Waterfall | Difference between Agile and Waterfall | EdurekaAgile vs Waterfall | Difference between Agile and Waterfall | Edureka
Agile vs Waterfall | Difference between Agile and Waterfall | EdurekaEdureka!
 
Scaling up task processing with Celery
Scaling up task processing with CeleryScaling up task processing with Celery
Scaling up task processing with CeleryNicolas Grasset
 
간단한 블로그를 만들며 Django 이해하기
간단한 블로그를 만들며 Django 이해하기간단한 블로그를 만들며 Django 이해하기
간단한 블로그를 만들며 Django 이해하기Kyoung Up Jung
 
IT Change Management Using JIRA
IT Change Management Using JIRAIT Change Management Using JIRA
IT Change Management Using JIRAAtlassian
 
Introduction à React JS
Introduction à React JSIntroduction à React JS
Introduction à React JSAbdoulaye Dieng
 
Design patterns - Exemples en Java
Design patterns - Exemples en JavaDesign patterns - Exemples en Java
Design patterns - Exemples en JavaOussama BEN KHIROUN
 
Formation Usine Logicielle gratuite par Ippon 2014
Formation Usine Logicielle gratuite par Ippon 2014Formation Usine Logicielle gratuite par Ippon 2014
Formation Usine Logicielle gratuite par Ippon 2014Ippon
 
Software architect design documentation template
Software architect design documentation templateSoftware architect design documentation template
Software architect design documentation templateSalim M Bhonhariya
 
Software Agility.pptx
Software Agility.pptxSoftware Agility.pptx
Software Agility.pptxZaid Shabbir
 

Was ist angesagt? (20)

EMC Documentum - xCP 2.x Troubleshooting
EMC Documentum - xCP 2.x TroubleshootingEMC Documentum - xCP 2.x Troubleshooting
EMC Documentum - xCP 2.x Troubleshooting
 
Introducing SAFe 5.0 the operating system for Business Agility
Introducing SAFe 5.0 the operating system for Business AgilityIntroducing SAFe 5.0 the operating system for Business Agility
Introducing SAFe 5.0 the operating system for Business Agility
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World Examples
 
An introduction to SQLAlchemy
An introduction to SQLAlchemyAn introduction to SQLAlchemy
An introduction to SQLAlchemy
 
Angular 11
Angular 11Angular 11
Angular 11
 
Agile vs Waterfall | Difference between Agile and Waterfall | Edureka
Agile vs Waterfall | Difference between Agile and Waterfall | EdurekaAgile vs Waterfall | Difference between Agile and Waterfall | Edureka
Agile vs Waterfall | Difference between Agile and Waterfall | Edureka
 
Sécurité des Applications Web avec Json Web Token (JWT)
Sécurité des Applications Web avec Json Web Token (JWT)Sécurité des Applications Web avec Json Web Token (JWT)
Sécurité des Applications Web avec Json Web Token (JWT)
 
Scaling up task processing with Celery
Scaling up task processing with CeleryScaling up task processing with Celery
Scaling up task processing with Celery
 
Cours design pattern m youssfi partie 3 decorateur
Cours design pattern m youssfi partie 3 decorateurCours design pattern m youssfi partie 3 decorateur
Cours design pattern m youssfi partie 3 decorateur
 
간단한 블로그를 만들며 Django 이해하기
간단한 블로그를 만들며 Django 이해하기간단한 블로그를 만들며 Django 이해하기
간단한 블로그를 만들며 Django 이해하기
 
IT Change Management Using JIRA
IT Change Management Using JIRAIT Change Management Using JIRA
IT Change Management Using JIRA
 
Angular Avancé
Angular AvancéAngular Avancé
Angular Avancé
 
Qualité de code et bonnes pratiques
Qualité de code et bonnes pratiquesQualité de code et bonnes pratiques
Qualité de code et bonnes pratiques
 
Introduction à React JS
Introduction à React JSIntroduction à React JS
Introduction à React JS
 
Design patterns - Exemples en Java
Design patterns - Exemples en JavaDesign patterns - Exemples en Java
Design patterns - Exemples en Java
 
Formation Usine Logicielle gratuite par Ippon 2014
Formation Usine Logicielle gratuite par Ippon 2014Formation Usine Logicielle gratuite par Ippon 2014
Formation Usine Logicielle gratuite par Ippon 2014
 
Software architect design documentation template
Software architect design documentation templateSoftware architect design documentation template
Software architect design documentation template
 
Introduction à React
Introduction à ReactIntroduction à React
Introduction à React
 
Angular.pdf
Angular.pdfAngular.pdf
Angular.pdf
 
Software Agility.pptx
Software Agility.pptxSoftware Agility.pptx
Software Agility.pptx
 

Ähnlich wie 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
 

Ähnlich wie 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...
 

Kürzlich hochgeladen

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
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
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Kürzlich hochgeladen (20)

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
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...
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

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