Python for AngularJS
AngularJS.$inject(Python)
Huh? Angular?
•

JavaScript framework for SPAs

•

“Extends” HTML vocabulary

•

Controllers, services, templates
Let’s begin
<html ng-app="app">
<head>
<script src=“https://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.js">
</script>
<script>

!
angular.module('app', [])
.controller('TradeCtrl', function ($scope) {
$scope.conversion = 0.00000268;
});

!
</script>
</head>
<body ng-controller="TradeCtrl">

!
<input type="text" ng-model="bitcoins" placeholder="Bitcoins">
<p>Wow! {{ bitcoins }} BTC = {{ (bitcoins / conversion)|number }} DOGE!</p>

!
</body>
</html>
But wait! Data!
•

Write a service in Angular
But wait! Data!
angular.module('app', [])

!
.factory('Exchange', function ($http) {
return {
getConversion: function () {
return $http.get('http://suchdoge.com/api/exchange/');
}
}
})

!
.controller('TradeCtrl', function ($scope, Exchange) {
Exchange.getConversion().then(function (result) {
$scope.conversion = result.conversion;
});
});
But wait! Data!
•

Write a service in Angular

•

Write an API endpoint in Python
But wait! Data!
import json
from django.http import HttpResponse
from doge.models import DogeConversion

!
def exchange(request):
"""API endpoint for requesting current BTC-DOGE exchange rate."""
conversion = DogeConversion.objects.latest('timestamp')
response = {'conversion': conversion.rate}
return HttpResponse(
json.dumps(response),
content_type='application/json'
)
But wait! Data!
•

Write a service in Angular

•

Write an API endpoint in Python

•

Ew, hard-coded URLs? Fix!
But wait! Data!
angular.module('app', [])

!
.config(function (RestangularProvider) {
RestangularProvider.setBaseUrl('/api');
})

!
.factory('Exchange', function (Restangular) {
return {
getConversion: function () {
return Restangular.all('exchange');
}
};
})
But wait! Data!
•

Write a service in Angular

•

Write an API endpoint in Python

•

Ew, hard-coded URLs? Fix!

•

Ew, hand-written API views? Fix!
But wait! Data!
from rest_framework import viewsets
from doge.models import DogeConversion

!
class DogeConversionViewSet(viewsets.ModelViewSet):
model = DogeConversion
Gotchas
•

Django and Jinja templates clash
.config(function ($interpolateProvider) {
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
})
Gotchas
•

Django and Jinja templates clash

•

CSRF tokens
.config(function ($httpProvider) {
var csrfToken = getCsrfToken(); // Implementation-dependent
$httpProvider.defaults.headers.common['X-CSRFToken'] = csrfToken;
})
Gotchas
•

Django and Jinja templates clash

•

CSRF tokens

•

Template partials
Jeff Schenck
CTO & Co-Founder
!
www.chewse.com
@jeffschenck
!

code github.com/jeffschenck/talk-2014-02-python-angularjs
slides www.slideshare.net/jmschenck/angular

More Related Content

KEY
I18n
PDF
Optimizing AngularJS Application
PPT
jQuery Intro
PPTX
REST API for your WP7 App
PDF
Angular Classy
PPTX
Intro to Rails Give Camp Atlanta
PPTX
Catalog display
PDF
Intro to-rails-webperf
I18n
Optimizing AngularJS Application
jQuery Intro
REST API for your WP7 App
Angular Classy
Intro to Rails Give Camp Atlanta
Catalog display
Intro to-rails-webperf

What's hot (20)

PDF
Webapps without the web
PDF
Build REST API clients for AngularJS
PDF
REST in AngularJS
PPTX
Apex & jQuery Mobile
PPTX
Angularjs Performance
PPTX
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
PPTX
Dash of ajax
PDF
Ruby on Rails - UNISO
PDF
iPhone Appleless Apps
PDF
Introduction to App Engine Development
PDF
Automated Testing in EmberJS
PDF
Unit Testing JavaScript Applications
PDF
Intro to UI-Router/TypeScript
PPT
PDF
Beyond DOM Manipulations: Building Stateful Modules with Events and Promises
PDF
Angular.JS: Do it right
PDF
Capybara with Rspec
PPTX
Tests in Javascript using Jasmine and Testacular
PDF
Introduction to plugin development
Webapps without the web
Build REST API clients for AngularJS
REST in AngularJS
Apex & jQuery Mobile
Angularjs Performance
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
Dash of ajax
Ruby on Rails - UNISO
iPhone Appleless Apps
Introduction to App Engine Development
Automated Testing in EmberJS
Unit Testing JavaScript Applications
Intro to UI-Router/TypeScript
Beyond DOM Manipulations: Building Stateful Modules with Events and Promises
Angular.JS: Do it right
Capybara with Rspec
Tests in Javascript using Jasmine and Testacular
Introduction to plugin development
Ad

Viewers also liked (10)

PPTX
Running Node Applications on iOS and Android
PDF
Where Node.JS Meets iOS
PDF
Intro to appcelerator
KEY
Titanium appcelerator kickstart
PPTX
TypeScript - Campus party 2013
PPTX
Node.js code tracing
PDF
최근 Javascript framework 조사
PPT
Android & iOS Automation Using Appium
PDF
Modern UI Development With Node.js
PDF
Create responsive websites with Django, REST and AngularJS
Running Node Applications on iOS and Android
Where Node.JS Meets iOS
Intro to appcelerator
Titanium appcelerator kickstart
TypeScript - Campus party 2013
Node.js code tracing
최근 Javascript framework 조사
Android & iOS Automation Using Appium
Modern UI Development With Node.js
Create responsive websites with Django, REST and AngularJS
Ad

Similar to Python for AngularJS (6)

PPTX
Single page application 05
PPT
AngularJS Mobile Warsaw 20-10-2014
PPTX
Angular js 1.0-fundamentals
PPT
Coffee@DBG - Exploring Angular JS
PPTX
Angular js
PPTX
AngularJs presentation
Single page application 05
AngularJS Mobile Warsaw 20-10-2014
Angular js 1.0-fundamentals
Coffee@DBG - Exploring Angular JS
Angular js
AngularJs presentation

Recently uploaded (20)

PDF
Applying Agentic AI in Enterprise Automation
PPTX
Information-Technology-in-Human-Society.pptx
PDF
Advancements in abstractive text summarization: a deep learning approach
PDF
Uncertainty-aware contextual multi-armed bandits for recommendations in e-com...
PPTX
Information-Technology-in-Human-Society (2).pptx
PPTX
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
PPTX
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
PDF
Optimizing bioinformatics applications: a novel approach with human protein d...
PDF
TicketRoot: Event Tech Solutions Deck 2025
PDF
The Digital Engine Room: Unlocking APAC’s Economic and Digital Potential thro...
PPTX
Report in SIP_Distance_Learning_Technology_Impact.pptx
PDF
FASHION-DRIVEN TEXTILES AS A CRYSTAL OF A NEW STREAM FOR STAKEHOLDER CAPITALI...
PDF
NewMind AI Journal Monthly Chronicles - August 2025
PDF
Human Computer Interaction Miterm Lesson
PDF
Ebook - The Future of AI A Comprehensive Guide.pdf
PDF
State of AI in Business 2025 - MIT NANDA
PDF
Slides World Game (s) Great Redesign Eco Economic Epochs.pdf
PDF
“Introduction to Designing with AI Agents,” a Presentation from Amazon Web Se...
PDF
Technical Debt in the AI Coding Era - By Antonio Bianco
PDF
GDG Cloud Southlake #45: Patrick Debois: The Impact of GenAI on Development a...
Applying Agentic AI in Enterprise Automation
Information-Technology-in-Human-Society.pptx
Advancements in abstractive text summarization: a deep learning approach
Uncertainty-aware contextual multi-armed bandits for recommendations in e-com...
Information-Technology-in-Human-Society (2).pptx
From XAI to XEE through Influence and Provenance.Controlling model fairness o...
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
Optimizing bioinformatics applications: a novel approach with human protein d...
TicketRoot: Event Tech Solutions Deck 2025
The Digital Engine Room: Unlocking APAC’s Economic and Digital Potential thro...
Report in SIP_Distance_Learning_Technology_Impact.pptx
FASHION-DRIVEN TEXTILES AS A CRYSTAL OF A NEW STREAM FOR STAKEHOLDER CAPITALI...
NewMind AI Journal Monthly Chronicles - August 2025
Human Computer Interaction Miterm Lesson
Ebook - The Future of AI A Comprehensive Guide.pdf
State of AI in Business 2025 - MIT NANDA
Slides World Game (s) Great Redesign Eco Economic Epochs.pdf
“Introduction to Designing with AI Agents,” a Presentation from Amazon Web Se...
Technical Debt in the AI Coding Era - By Antonio Bianco
GDG Cloud Southlake #45: Patrick Debois: The Impact of GenAI on Development a...

Python for AngularJS

  • 2. Huh? Angular? • JavaScript framework for SPAs • “Extends” HTML vocabulary • Controllers, services, templates
  • 3. Let’s begin <html ng-app="app"> <head> <script src=“https://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.js"> </script> <script> ! angular.module('app', []) .controller('TradeCtrl', function ($scope) { $scope.conversion = 0.00000268; }); ! </script> </head> <body ng-controller="TradeCtrl"> ! <input type="text" ng-model="bitcoins" placeholder="Bitcoins"> <p>Wow! {{ bitcoins }} BTC = {{ (bitcoins / conversion)|number }} DOGE!</p> ! </body> </html>
  • 4. But wait! Data! • Write a service in Angular
  • 5. But wait! Data! angular.module('app', []) ! .factory('Exchange', function ($http) { return { getConversion: function () { return $http.get('http://suchdoge.com/api/exchange/'); } } }) ! .controller('TradeCtrl', function ($scope, Exchange) { Exchange.getConversion().then(function (result) { $scope.conversion = result.conversion; }); });
  • 6. But wait! Data! • Write a service in Angular • Write an API endpoint in Python
  • 7. But wait! Data! import json from django.http import HttpResponse from doge.models import DogeConversion ! def exchange(request): """API endpoint for requesting current BTC-DOGE exchange rate.""" conversion = DogeConversion.objects.latest('timestamp') response = {'conversion': conversion.rate} return HttpResponse( json.dumps(response), content_type='application/json' )
  • 8. But wait! Data! • Write a service in Angular • Write an API endpoint in Python • Ew, hard-coded URLs? Fix!
  • 9. But wait! Data! angular.module('app', []) ! .config(function (RestangularProvider) { RestangularProvider.setBaseUrl('/api'); }) ! .factory('Exchange', function (Restangular) { return { getConversion: function () { return Restangular.all('exchange'); } }; })
  • 10. But wait! Data! • Write a service in Angular • Write an API endpoint in Python • Ew, hard-coded URLs? Fix! • Ew, hand-written API views? Fix!
  • 11. But wait! Data! from rest_framework import viewsets from doge.models import DogeConversion ! class DogeConversionViewSet(viewsets.ModelViewSet): model = DogeConversion
  • 12. Gotchas • Django and Jinja templates clash .config(function ($interpolateProvider) { $interpolateProvider.startSymbol('[['); $interpolateProvider.endSymbol(']]'); })
  • 13. Gotchas • Django and Jinja templates clash • CSRF tokens .config(function ($httpProvider) { var csrfToken = getCsrfToken(); // Implementation-dependent $httpProvider.defaults.headers.common['X-CSRFToken'] = csrfToken; })
  • 14. Gotchas • Django and Jinja templates clash • CSRF tokens • Template partials
  • 15. Jeff Schenck CTO & Co-Founder ! www.chewse.com @jeffschenck ! code github.com/jeffschenck/talk-2014-02-python-angularjs slides www.slideshare.net/jmschenck/angular