I
I
Ivan2015-06-16 16:54:13
Django
Ivan, 2015-06-16 16:54:13

How to use Django on the backend to make routing in AngularJS?

Good day.
Can you please tell me how to make client-side routing using Django + Angular?
In Angular's config I wrote the following:

.config(['$routeProvider', function($routeProvider) {

            $routeProvider
            .when('/', {

              controller: 'MyCtrl',
              templateUrl: 'views/main.html'

            })
            .when('/api/profile/:id', {

              controller: 'TestController',
              templateUrl: 'views/profile.html'

            })
            .otherwise({

              redirectTo: '/'

            })

In index.html
<div ng-view></div>
When trying to go to the main page in the firebug, it gives an error:
GET http://localhost:8000/views/main.html 404 (NOT FOUND)
Error: [$compile:tpload] http://errors.angularjs.org/1.3.16/$compile/tpload?p0=views%2Fmain.html
    at Error (native)
    at http://localhost:8000/static/js/vendors/angular.min.js:6:417
    at http://localhost:8000/static/js/vendors/angular.min.js:137:174
    at http://localhost:8000/static/js/vendors/angular.min.js:112:182
    at m.$get.m.$eval (http://localhost:8000/static/js/vendors/angular.min.js:126:250)
    at m.$get.m.$digest (http://localhost:8000/static/js/vendors/angular.min.js:123:365)
    at m.$get.m.$apply (http://localhost:8000/static/js/vendors/angular.min.js:127:12)
    at l (http://localhost:8000/static/js/vendors/angular.min.js:81:327)
    at P (http://localhost:8000/static/js/vendors/angular.min.js:85:449)
    at XMLHttpRequest.H.onload (http://localhost:8000/static/js/vendors/angular.min.js:86:462)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2015-06-16
@ATNC

templateUrl: 'views/main.html'should refer to the directory where you have the statics. In other words, put this template where you have all the css and js files, and write the correct path to it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question