Django Rest Angular Guide
Django Rest Angular Guide
Hi, Im Hannes.
@hanneshapke
hanneshapke.github.io
Github: https://github.com/hanneshapke/fruitloop_django
Github: https://github.com/hanneshapke/fruitloop_angular
is synchronous.
http://python-notes.curiousefficiency.org/en/latest/pep_ideas/async_programming.html
{}
http://www.airpair.com/js/javascript-framework-comparison
because it is hip
Step #1
Create an API endpoint
to your Django model
REST
What to do?
Image: http://4gbloggingcrew.global2.vic.edu.au/files/2014/07/boom-2gjd45e.jpg
Hey Django,
meet AngularJS.
Step #2
Set up your js environment
and install AngularJS
What?
A new eco system!
Based on node.js?
Bower.io
Install packages:
`bower install [package] --save`
What to do?
{!
3
4 }!
"directory": "fruitloop_angular/assets/js/",!
"json": "bower.json"!
Step #3
Create a
static AngularJS site
Angular offers
Controllers - Changes site behaviour
Services - Provides data access (e.g. REST)
Directives - Create your own DOM elements
What to do?
Step #4
Use {% verbatim %}
{{ isnt {{
Step #5
Make AngularJS talk
to your API
What to do?
Sample code
1 var fruitServices = angular.module('fruitServices', ['ngResource']);!
2 fruitServices.factory('FruitLocationService', ['$resource',!
3
function($resource){!
4
return $resource('api\\/', {}, {!
5
query: {method:'GET', params:{}, isArray: true}!
6
});!
7
}!
8 ]);!
Step #6
Take full advantage of the
Django REST Framework
Thoughts
Step #7
Use $promise,
but dont promise too much
Example
Thoughts
Step #8
Make your form
talk to your API
What to do?
Step #9
Clean up your settings.py
What to do?
Step #10
Document your API
What to do?
Small Hints
Use AngularJS
Constants
1 angular.module('myApp')!
2
.constant('settings', {!
3
// mimic the Django STATIC_URL variable!
4
STATIC_URL: '/static/'!
5
});!
Decide!
urls.py vs. ng-route
What about
site performance?
Vielen Dank.
hannes.hapke@gmail.com
@hanneshapke
hanneshapke.github.io
Resources
Lightweight Django:
http://shop.oreilly.com/product/0636920032502.do#
Using Tasty-pie:
http://glynjackson.org/weblog/entry/django-angular.html