search

Home  >  Q&A  >  body text

angular.js - Problems with combining angularjs and django

I wrote the frontend using angualrjs, and then wrote the backend using django. How can I combine the two?
There are main pages and templates in angularjs, and they are also available in django.
Enter a URL. What does Django return when getting the URL? Are all templates and pages, js, and css returned?

给我你的怀抱给我你的怀抱2781 days ago699

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-05-15 16:54:41

    Angular only requests the page from the background during the first request. Subsequent requests request background data to update the page by calling the background API.

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-15 16:54:41

    Use Django to build RESTful API

    reply
    0
  • 为情所困

    为情所困2017-05-15 16:54:41

    You can refer to this my blog: phodaldev

    • Tastypie makes RESTful API
    • The template is written in the Django template

    As follows

    {% block main %}
    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular.min.js"></script>
    <script type="text/javascript">
     var blogposts = angular.module('blogposts',[]);
    blogposts.config(function($interpolateProvider) {
      $interpolateProvider.startSymbol('{[{');
      $interpolateProvider.endSymbol('}]}');
    });
     blogposts.controller('blogController', function($scope, $http) {
         $http.get('/api/v1/url/?limit=600&format=json').success(function(data) {
             $scope.posts = data["objects"];
        });
     });
    </script>
    <p ng-app="blogposts">
    <p class="posts"  ng-controller="blogController">
    <ul>
    <li ng-repeat="post in posts"><a href="/blog/{[{post.slug}]}">{[{post.title}]}</a></li>
    </ul>
    </p>
    </p>
    {% endblock %}
    

    reply
    0
  • Cancelreply