Loading html from an url template in AngularJS directive (in a django application)

How to load html from templateURLinto AngularJS directive in django-built application. Whenever I specify a URL in a variable templateURL, it reaches the django server. How can i implement this? Can I give the django url in a variable templateURLin directives and display the HTML there in django? What is the right way to do this?

My directive:

app.directive('test', function()
{
  return{

  restrict: 'E',
  templateUrl: 'test.html'

}});

It reaches django's server someURL/test.htmland returns 404.

Can I implement this method?

app.directive('test', function()
{
  return{
  restrict: 'E',
  templateUrl: 'app/test'

}});

and in django urls.py

url(r'^test/$', TemplateView.as_view(template_name='test.html'))

Is this a good way to do this? What is the right way?

+4
source share
4 answers

:

.

urls.py

url :

templateUrl: 'static/test.html'
+6

.

test.html - Django, , Angular, , .

- - Angular URL. , Angular.

+2

,

http://www.verdantrefuge.com/writing/2013/angularjs-changing-app-path-base-element/

:

<base href="{% static 'js/vendor/myapp/app/' %}" />
<script src="js/Module.js"></script>

templateUrl :

(function () {
'use strict';
angular

    .module('site.project.app')
    .directive('myDirective', [myDirective])
;
function myDirective() {

    return {
        restrict: 'E',
        replace: true,
        controller: 'MyCtrl',
        templateUrl: 'partials/my-directive.html',
        link: function (scope, elem, attrs) {
        }

   }
}
})();
+2

Angular , , URL, , , URL- . , URL- django , , .

, , , : URL-, , , , django - templatetag , .

0

Source: https://habr.com/ru/post/1568736/


All Articles