我想添加到我的Django项目Angularjs,但是我的app.js没有加载。但是当我去那里的http://127.0.0.1:8000/static/js/app.js
时。不明白,我做错了。
base.html文件
...
{% block content %}
{% endblock %}
...
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<script src="{% static 'js/ie10-viewport-bug-workaround.js' %}"></script>
<script src="{% static 'js/angular.min.js' %}"></script>
<script src="{% static 'js/angular-route.js' %}"></script>
{% block extra_javascript %}{% endblock extra_javascript %}
内容-template.html
{% extends 'base.html' %}
{% load staticfiles %}
{% block content %}
...
<div class="container" ng-app="test">
<div ng-controller="testCtrl">
<div class="data">
</div>
<button ng-click="save()">Click</button>
</div>
</div>
{% endblock %}
{% block extra_javascript %}
<script scr="{% static 'js/app.js' %}"></script>
{% endblock extra_javascript %}
app.js
app = angular.module('test', [])
.config(function ($interpolateProvider, $httpProvider, $resourceProvider){
$interpolateProvider.startSymbol('[[').endSymbol(']]');
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
$resourceProvider.defaults.stripTrailingSlashes = false;
});
app.controller('testCtrl', ['$scope', function($scope){
$scope.num = 0;
$scope.save = function(){
$(".data").html("Click" + $scope.num);
$scope.num +=1;
};
}]);
查看-来源