Seperate Django Rest framework app and Angularjs app , how do they communicate? -
i'm new angularjs , i'm trying make angularjs application consumes json django rest framework api , , have been advised seperate project 2 seperate apps 1 django , othet angularjs (even using 2 different ides) , question how can set angularjs app , django app can communicate each other knowing i'm working on localhost ? how django rest framework respond angularjs requests ? thank
the simple way have django template view serving client (angularjs) application. use nodejs + express + grunt/gulp serve client application on port on localhost , set cors in rest framework. either way you'll $http.get/post/whatever
calls django host:port
app client application.
i use second approach.
views.py
class homepageview(templateview): template_name = 'home.html'
urls.py*
urlpatterns = patterns('public.views', url(r'^$', homepageview.as_view(), name='home'),
templates/home.html
<!doctype html> {% load i18n %} {% load staticfiles %} {% load compress %} <html lang="en"> <head> <meta charset="utf-8"/> ... {% compress css %} <link rel="stylesheet" href="{% static "libs/bootstrap/css/bootstrap.css" %}"> ... {% endcompress %} </head> <body ng-app="myapp"> ... {% compress js %} <script src="{% static "libs/jquery/jquery.js" %}"></script> ... <script src="{% static "js/my-app/controllers/my-controller.js" %}"></script> .... {% endcompress %} </body>
for angularjs part use gulp, browserify , lot of other stuff. please take boilerplate grain of salt, came specific set of reasons.
Comments
Post a Comment